Skip to content

Commit

Permalink
format pod CPU and memory usage before returning
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Oct 19, 2023
1 parent a7ee18d commit 52b4e5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions pkg/helmvm/helmvm_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ func nodeMetrics(ctx context.Context, client kubernetes.Interface, metricsClient
podTotalCPU := 0.0
for _, container := range podMetrics.Containers {
if container.Usage.Memory() != nil {
podTotalMemory += float64(container.Usage.Memory().Value()) / math.Pow(2, 30)
podTotalMemory += float64(container.Usage.Memory().Value()) / math.Pow(2, 20)
}
if container.Usage.Cpu() != nil {
podTotalCPU += container.Usage.Cpu().AsApproximateFloat64()
podTotalCPU += container.Usage.Cpu().AsApproximateFloat64() * 1000
}
}
newInfo.Memory = podTotalMemory
newInfo.CPU = podTotalCPU
newInfo.Memory = fmt.Sprintf("%.1f MB", podTotalMemory)
newInfo.CPU = fmt.Sprintf("%.1f m", podTotalCPU)
}

podInfo = append(podInfo, newInfo)
Expand Down
10 changes: 5 additions & 5 deletions pkg/helmvm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type NodeConditions struct {
}

type PodInfo struct {
Name string `json:"name"`
Status string `json:"status"`
Namespace string `json:"namespace"`
CPU float64 `json:"cpu"`
Memory float64 `json:"memory"`
Name string `json:"name"`
Status string `json:"status"`
Namespace string `json:"namespace"`
CPU string `json:"cpu"`
Memory string `json:"memory"`
}

0 comments on commit 52b4e5c

Please sign in to comment.