-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (49 loc) · 1.56 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"fmt"
"os"
"time"
graph "kubernetes-go/graph"
"math"
"github.com/aquasecurity/table"
)
func main() {
namespace := flag.String("namespace", "", "Enter Namespace")
entity := flag.String("entity", "", "Enter pods/ nodes (For nodes only use entity flag) (Required)")
help := flag.String("h", "","shows Usage of the command line arguments")
flag.Parse()
if *help == ""{
flag.PrintDefaults()
}
if *namespace == "" {
fmt.Println("Namespace not needed for nodes")
}
if *entity == "pods" {
start := time.Now()
fmt.Println("Generating metrics.............")
data, _ := graph.GetPodMetrics(*namespace)
end := time.Now()
elapsed := end.Sub(start)
fmt.Println("Time taken to get the metrics: ", math.Round(elapsed.Seconds()), "s")
t := table.New(os.Stdout)
t.SetHeaders("Node Name", "Pod Name", "Container Name", "CPU value", "CPU Percentage", "Memory Value", "Memory Percentage")
for _, v := range data {
t.AddRow(v[0], v[1], v[2], v[3], v[4], v[5], v[6])
}
t.Render()
} else if *entity == "nodes" {
start := time.Now()
fmt.Println("Generating metrics.............")
data := graph.GetNodeMetrics()
end := time.Now()
elapsed := end.Sub(start)
fmt.Println("Time taken to get the metrics: ", math.Round(elapsed.Seconds()), "s")
t := table.New(os.Stdout)
t.SetHeaders("Node Name", "CPU Value", "Node CPU usage", "CPU Percentage", "Memory Value", "Node Memory usage", "Memory Percentage", "No of pods")
for _, v := range data {
t.AddRow(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7])
}
t.Render()
}
}