From e4f101eb15bee771d5fc779e073db5bdf8310a8a Mon Sep 17 00:00:00 2001 From: Wouter Verlaek Date: Wed, 5 Oct 2022 10:01:48 +0000 Subject: [PATCH 1/2] chore(gitpod-cli): Update top table output format --- components/gitpod-cli/cmd/top.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/components/gitpod-cli/cmd/top.go b/components/gitpod-cli/cmd/top.go index eac607102cebe4..f6e57ea83c0c47 100644 --- a/components/gitpod-cli/cmd/top.go +++ b/components/gitpod-cli/cmd/top.go @@ -89,24 +89,22 @@ func outputWorkspaceClass(workspaceClass *supervisor.WorkspaceInfoResponse_Works func outputTable(workspaceResources *supervisor.ResourcesStatusResponse) { table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"CPU (millicores)", "Memory (bytes)"}) - table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: false}) - table.SetCenterSeparator("|") + table.SetBorder(false) + table.SetColumnSeparator(":") cpuFraction := int64((float64(workspaceResources.Cpu.Used) / float64(workspaceResources.Cpu.Limit)) * 100) memFraction := int64((float64(workspaceResources.Memory.Used) / float64(workspaceResources.Memory.Limit)) * 100) cpu := fmt.Sprintf("%dm/%dm (%d%%)", workspaceResources.Cpu.Used, workspaceResources.Cpu.Limit, cpuFraction) - memory := fmt.Sprintf("%dMi/%dMi (%d%%)\n", workspaceResources.Memory.Used/(1024*1024), workspaceResources.Memory.Limit/(1024*1024), memFraction) - - colors := []tablewriter.Colors{} + memory := fmt.Sprintf("%dMi/%dMi (%d%%)", workspaceResources.Memory.Used/(1024*1024), workspaceResources.Memory.Limit/(1024*1024), memFraction) + var cpuColors, memoryColors []tablewriter.Colors if !noColor && utils.ColorsEnabled() { - cpuColor := getColor(workspaceResources.Cpu.Severity) - memoryColor := getColor(workspaceResources.Memory.Severity) - colors = []tablewriter.Colors{{cpuColor}, {memoryColor}} + cpuColors = []tablewriter.Colors{nil, {getColor(workspaceResources.Cpu.Severity)}} + memoryColors = []tablewriter.Colors{nil, {getColor(workspaceResources.Memory.Severity)}} } - table.Rich([]string{cpu, memory}, colors) + table.Rich([]string{"CPU (millicores)", cpu}, cpuColors) + table.Rich([]string{"Memory (bytes)", memory}, memoryColors) table.Render() } From 674a6392797b4a54c1fe04093396793e72a073fa Mon Sep 17 00:00:00 2001 From: Wouter Verlaek Date: Wed, 5 Oct 2022 10:22:45 +0000 Subject: [PATCH 2/2] Move workspace class to table --- components/gitpod-cli/cmd/top.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/components/gitpod-cli/cmd/top.go b/components/gitpod-cli/cmd/top.go index f6e57ea83c0c47..ede87d94fe79ef 100644 --- a/components/gitpod-cli/cmd/top.go +++ b/components/gitpod-cli/cmd/top.go @@ -75,21 +75,21 @@ var topCmd = &cobra.Command{ fmt.Println(string(content)) return } - outputWorkspaceClass(data.WorkspaceClass) - outputTable(data.Resources) + outputTable(data.Resources, data.WorkspaceClass) }, } -func outputWorkspaceClass(workspaceClass *supervisor.WorkspaceInfoResponse_WorkspaceClass) { +func formatWorkspaceClass(workspaceClass *supervisor.WorkspaceInfoResponse_WorkspaceClass) string { if workspaceClass == nil || workspaceClass.DisplayName == "" { - return + return "" } - fmt.Printf("%s: %s\n\n", workspaceClass.DisplayName, workspaceClass.Description) + return fmt.Sprintf("%s: %s", workspaceClass.DisplayName, workspaceClass.Description) } -func outputTable(workspaceResources *supervisor.ResourcesStatusResponse) { +func outputTable(workspaceResources *supervisor.ResourcesStatusResponse, workspaceClass *supervisor.WorkspaceInfoResponse_WorkspaceClass) { table := tablewriter.NewWriter(os.Stdout) table.SetBorder(false) + table.SetColWidth(50) table.SetColumnSeparator(":") cpuFraction := int64((float64(workspaceResources.Cpu.Used) / float64(workspaceResources.Cpu.Limit)) * 100) @@ -103,6 +103,7 @@ func outputTable(workspaceResources *supervisor.ResourcesStatusResponse) { memoryColors = []tablewriter.Colors{nil, {getColor(workspaceResources.Memory.Severity)}} } + table.Append([]string{"Workspace class", formatWorkspaceClass(workspaceClass)}) table.Rich([]string{"CPU (millicores)", cpu}, cpuColors) table.Rich([]string{"Memory (bytes)", memory}, memoryColors)