-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster-capacity.py
62 lines (49 loc) · 2.01 KB
/
cluster-capacity.py
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
59
60
61
62
## Generate table to parse:
#
# kubectl get nodes -o custom-columns=NAME:.metadata.name,TYPE:.metadata.labels.nodetype,CPU:.status.capacity.cpu,MEMORY:.status.capacity.memory,DISK:.status.capacity.ephemeral-storage --sort-by .metadata.labels.nodetype >> output.txt
f = open('output.txt');
f.readline(); # skip header row
aggregated = {
"computer": { "cpu": 0, "memory": 0, "disk": 0, "nodes": 0 }, # Memory and Disk in Ki
"edge": { "cpu": 0, "memory": 0, "disk": 0, "nodes": 0 },
"server": { "cpu": 0, "memory": 0, "disk": 0, "nodes": 0 },
}
for line in f:
columns = line.split()
nodetype = columns[1]
cpu = int(columns[2])
memory = int(columns[3].split('Ki')[0])
disk = int(columns[4].split('Ki')[0])
aggregated[nodetype]["cpu"] = aggregated[nodetype]["cpu"] + cpu
aggregated[nodetype]["memory"] = aggregated[nodetype]["memory"] + memory
aggregated[nodetype]["disk"] = aggregated[nodetype]["disk"] + disk
aggregated[nodetype]["nodes"] += 1
cpu = 0
memory = 0
disk = 0
nodes = 0
for nodetype in aggregated:
print(nodetype, aggregated[nodetype])
cpu += aggregated[nodetype]["cpu"]
memory += aggregated[nodetype]["memory"]
disk += aggregated[nodetype]["disk"]
nodes += aggregated[nodetype]["nodes"]
def sizeof_fmt(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"
print('')
print('Total CPUs:', cpu)
for nodetype in aggregated:
print('\t'+nodetype+":", aggregated[nodetype]["cpu"])
print('Total Memory:', sizeof_fmt(memory*1024))
for nodetype in aggregated:
print('\t'+nodetype+":", sizeof_fmt(aggregated[nodetype]["memory"]*1024))
print('Total Disk:', sizeof_fmt(disk*1024))
for nodetype in aggregated:
print('\t'+nodetype+":", sizeof_fmt(aggregated[nodetype]["disk"]*1024))
print('Total Nodes:', nodes)
for nodetype in aggregated:
print('\t'+nodetype+":", aggregated[nodetype]["nodes"])