Skip to content

Commit

Permalink
feat: add ip column
Browse files Browse the repository at this point in the history
  • Loading branch information
miltlima committed Jul 31, 2023
1 parent 8efbd8c commit e0e8d04
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"kom/kube"
"os"
"strings"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -45,7 +46,7 @@ func showNodesMetrics(cmd *cobra.Command, args []string) {
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Node", "CPU Usage %", "Memory Usage %"})
table.SetHeader([]string{"Node", "CPU Usage %", "Memory Usage %", "IP"})

for _, node := range nodes.Items {
nodeName := node.Name
Expand All @@ -58,13 +59,17 @@ func showNodesMetrics(cmd *cobra.Command, args []string) {
cpuUsage := metrics.Usage.Cpu().MilliValue() / 10
coloredCPU := getColorValue(int(cpuUsage))

// memoryUsage := metrics.Usage.Memory().Value() / (1024 * 1024)
memoryUsage := float64(metrics.Usage.Memory().Value()) / float64(node.Status.Capacity.Memory().Value()) * 100.0
coloredMemory := getColorValue(int(memoryUsage))

// row := []string{nodeName, fmt.Sprintf("%d", coloredCPU), fmt.Sprintf("%d", coloredMemory)}
row := []string{nodeName, coloredCPU, coloredMemory}
var nodeIPs []string
for _, address := range node.Status.Addresses {
if address.Type == corev1.NodeInternalIP || address.Type == corev1.NodeExternalIP {
nodeIPs = append(nodeIPs, address.Address)
}
}

row := []string{nodeName, coloredCPU, coloredMemory, strings.Join(nodeIPs, ", ")}
table.Append(row)

}
Expand Down

0 comments on commit e0e8d04

Please sign in to comment.