Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 1a1b6e3

Browse files
committed
Remove resource top utilization metrics
1 parent eff753a commit 1a1b6e3

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

internal/cmd/resourcemanager.go

+29-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func makeResourceCmd() *cobra.Command {
1616
cmd := &cobra.Command{
1717
Use: "resources",
18-
Short: "manager Coder resources with platform-level context (users, organizations, environments)",
18+
Short: "manage Coder resources with platform-level context (users, organizations, environments)",
1919
Hidden: true,
2020
}
2121
cmd.AddCommand(resourceTop())
@@ -141,8 +141,10 @@ func printResourceTop(writer io.Writer, groups []groupable, labeler envLabeler)
141141

142142
var userResources []aggregatedResources
143143
for _, group := range groups {
144-
// truncate user names to ensure tabwriter doesn't push our entire table too far
145-
userResources = append(userResources, aggregatedResources{groupable: group, resources: aggregateEnvResources(group.environments())})
144+
userResources = append(
145+
userResources,
146+
aggregatedResources{groupable: group, resources: aggregateEnvResources(group.environments())},
147+
)
146148
}
147149
sort.Slice(userResources, func(i, j int) bool {
148150
return userResources[i].cpuAllocation > userResources[j].cpuAllocation
@@ -220,7 +222,30 @@ type resources struct {
220222
}
221223

222224
func (a resources) String() string {
223-
return fmt.Sprintf("[cpu: alloc=%.1fvCPU, util=%.1f]\t[mem: alloc=%.1fGB, util=%.1f]", a.cpuAllocation, a.cpuUtilization, a.memAllocation, a.memUtilization)
225+
return fmt.Sprintf(
226+
"[cpu: alloc=%.1fvCPU]\t[mem: alloc=%.1fGB]",
227+
a.cpuAllocation, a.memAllocation,
228+
)
229+
230+
// TODO@cmoog: consider adding the utilization info once a historical average is considered or implemented
231+
// return fmt.Sprintf(
232+
// "[cpu: alloc=%.1fvCPU, util=%s]\t[mem: alloc=%.1fGB, util=%s]",
233+
// a.cpuAllocation, a.cpuUtilPercentage(), a.memAllocation, a.memUtilPercentage(),
234+
// )
235+
}
236+
237+
func (a resources) cpuUtilPercentage() string {
238+
if a.cpuAllocation == 0 {
239+
return "N/A"
240+
}
241+
return fmt.Sprintf("%.1f%%", a.cpuUtilization/a.cpuAllocation*100)
242+
}
243+
244+
func (a resources) memUtilPercentage() string {
245+
if a.memAllocation == 0 {
246+
return "N/A"
247+
}
248+
return fmt.Sprintf("%.1f%%", a.memUtilization/a.memAllocation*100)
224249
}
225250

226251
// truncate the given string and replace the removed chars with some replacement (ex: "...")

0 commit comments

Comments
 (0)