-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
57 lines (44 loc) · 1.12 KB
/
resources.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
package main
import (
"fmt"
"os"
"text/tabwriter"
)
// Help function
func resourceHelp() {
fmt.Println("Usage: proxmox resources [options]")
fmt.Println("List resource distribution between nodes")
fmt.Println("Options:")
fmt.Println(" -h, --help")
fmt.Println("Examples:")
fmt.Println(" proxmox resources")
}
func resources() {
// get options from parameters
params := os.Args[2:]
if checkParams(params, "help", false) {
resourceHelp()
os.Exit(0)
}
listAllResources()
}
// List all node resources
func listAllResources() {
// create tabwriter
tabWriter := new(tabwriter.Writer)
tabWriter.Init(os.Stdout, 5, 8, 1, '\t', 0)
// print header
fmt.Fprintln(tabWriter, "Node\tCPU (%)\tMemory Used (%)\tVMs\t")
fmt.Fprintln(tabWriter, "----\t---\t------\t-------\t")
// loop nodes
for _, node := range nodes {
// get node resources
cpu := node.CPU / 100
memory := float64(node.Memory.Total) / float64(node.Memory.Used)
vms := len(node.VirtualMachines)
// print node resources
fmt.Fprintf(tabWriter, "%s\t%.2f\t%.2f\t%d\t\n", node.Name, cpu, memory, vms)
}
// flush tabwriter
tabWriter.Flush()
}