func (factory *AppExaminerCommandFactory) printInstanceSummary(writer io.Writer, actualInstances []app_examiner.InstanceInfo) { w := tabwriter.NewWriter(writer, minColumnWidth, 8, 1, '\t', 0) printHorizontalRule(w, "=") fmt.Fprintf(w, fmt.Sprintf("%s\t%s\t%s\t%s\t%s\t%s\n", "Instance", colors.NoColor("State")+" ", "Crashes", "CPU", "Memory", "Uptime"), ) printHorizontalRule(w, "-") for _, instance := range actualInstances { metricsSlice := []string{"N/A", "N/A"} if instance.HasMetrics { metricsSlice = []string{ fmt.Sprintf("%.2f%%", instance.Metrics.CpuPercentage), fmt.Sprintf("%s", bytefmt.ByteSize(instance.Metrics.MemoryBytes)), } } if instance.PlacementError == "" && instance.State != "CRASHED" { uptime := factory.clock.Now().Sub(time.Unix(0, instance.Since)) roundedUptime := uptime - (uptime % time.Second) fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", strconv.Itoa(instance.Index), presentation.PadAndColorInstanceState(instance), strconv.Itoa(instance.CrashCount), strings.Join(metricsSlice, "\t"), fmt.Sprint(roundedUptime), ) } else { fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", strconv.Itoa(instance.Index), presentation.PadAndColorInstanceState(instance), strconv.Itoa(instance.CrashCount), strings.Join(metricsSlice, "\t"), "N/A", ) } } w.Flush() }
Context("when there is not a placement error", func() { It("colors UNCLAIMED cyan", func() { instanceInfo := app_examiner.InstanceInfo{State: string(receptor.ActualLRPStateUnclaimed)} Expect(presentation.ColorInstanceState(instanceInfo)).To(Equal(colors.Cyan(string(receptor.ActualLRPStateUnclaimed)))) }) }) It("colors INVALID red", func() { instanceInfo := app_examiner.InstanceInfo{State: string(receptor.ActualLRPStateInvalid)} Expect(presentation.ColorInstanceState(instanceInfo)).To(Equal(colors.Red(string(receptor.ActualLRPStateInvalid)))) }) It("colors CRASHED red", func() { instanceInfo := app_examiner.InstanceInfo{State: string(receptor.ActualLRPStateCrashed)} Expect(presentation.ColorInstanceState(instanceInfo)).To(Equal(colors.Red(string(receptor.ActualLRPStateCrashed)))) }) }) Describe("PadAndColorInstanceState", func() { It("pads and colors States shorter than UNCLAIMED", func() { instanceInfo := app_examiner.InstanceInfo{State: string(receptor.ActualLRPStateRunning)} Expect(presentation.PadAndColorInstanceState(instanceInfo)).To(Equal(colors.Green(string(receptor.ActualLRPStateRunning)) + " ")) }) It("does not pad UNCLAIMED state", func() { instanceInfo := app_examiner.InstanceInfo{State: string(receptor.ActualLRPStateUnclaimed)} Expect(presentation.PadAndColorInstanceState(instanceInfo)).To(Equal(colors.Cyan(string(receptor.ActualLRPStateUnclaimed)))) }) }) })