-
Notifications
You must be signed in to change notification settings - Fork 1
/
unownednodes
executable file
·63 lines (55 loc) · 1.64 KB
/
unownednodes
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
#!/usr/bin/env bash
declare -iA nodes
declare -iA owned_nodes
declare -iA online_nodes
declare -iA unowned_nodes
for l in $(qhost \
| grep -o node-. \
| uniq -c \
| awk '{ print $1":"$2 }' \
);
do
node_count="${l%%:*}"
node_type="${l##*:}"
nodes+=(["$node_type"]="$node_count")
done
for l in $(qhost \
| grep -v ' - ' \
| grep -o node-. \
| uniq -c \
| awk '{ print $1":"$2 }' \
);
do
node_count="${l%%:*}"
node_type="${l##*:}"
online_nodes+=(["$node_type"]="$node_count")
done
for l in $(cat /opt/geassist/etc/nodeowners \
| grep -o node-. \
| uniq -c \
| awk '{ print $1":"$2 }' \
);
do
node_count="${l%%:*}"
node_type="${l##*:}"
owned_nodes+=(["$node_type"]="$node_count")
done
#echo "Nodes keys: ${!nodes[@]}"
#echo "Owned nodes keys: ${!owned_nodes[@]}"
declare total_unowned=0
declare total_online=0
declare total_all=0
declare output=""
for key in "${!nodes[@]}"; do
#echo "${nodes[$key]} - ${owned_nodes[$key]:-0}"
#echo "Nodes ($key): ${nodes[$key]}"
#echo "Owned nodes ($key): ${owned_nodes[$key]}"
unowned_nodes[$key]=$(( ${nodes[$key]} - ${owned_nodes[$key]:-0} ))
output+="$key: ${unowned_nodes[$key]}/${online_nodes[$key]:-0}/${nodes[$key]}"$'\n'
total_unowned=$(( total_unowned + ${unowned_nodes[$key]} ))
total_online=$(( total_online + ${online_nodes[$key]:-0} ))
total_all=$(( total_all + ${nodes[$key]} ))
done
echo "type: unowned/online/total"
echo -n "$output" | sort
echo "total: $total_unowned/$total_online/$total_all"