-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslurm-overview-v1
More file actions
227 lines (196 loc) · 5.93 KB
/
Copy pathslurm-overview-v1
File metadata and controls
227 lines (196 loc) · 5.93 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env bash
####################### TUNABLES! #########################
TOPUSERNUM=5 # how many top users to show
NUM_WIDTH=4 # width of number values
USE_COLOR=${USE_COLOR:-1} # 1 = use color; anything else = don't use color
# Default list of partitions to show
if [ "${PARTS:-none}" = none ]; then
PARTS="cpu gpu test"
fi
# Color gauge filler
#CHAR="▒"
CHAR="▓"
#CHAR="█"
#CHAR="░"
#CHAR="☢"
#CHAR="☷"
#CHAR="⛶"
#CHAR="▶"
#CHAR="▦"
#CHAR="▧"
# Non-color gauge fillers
declare -a CHARS
CHARS=('▦' '.' 'x')
# colors for alloc/idle/failed numbers
C_A="2"
C_I="4"
C_F="1"
# -- codes for colors
C_ALLOC="\\e[4${C_A};37m"
C_IDLE="\\e[4${C_I}m"
C_FAILED="\\e[4${C_F}m"
# -- codes for colors of corresponding header (just inverted, e.g.)
C_ALLOC_H="\\e[3${C_A};47m"
C_IDLE_H="\\e[3${C_I}m"
C_FAILED_H="\\e[3${C_F}m"
########################## SCRIPT! #########################
PART_WIDTH=0
for i in ${PARTS}; do
if [ ${PART_WIDTH} -lt ${#i} ]; then PART_WIDTH=${#i}; fi
done
declare -A states
declare -A users
# CHAR WIDTH color value color2 value2 ...
colorBar() {
local c width len ignore val total new
c=${1:0:1}
c=${c:-#}
if [ $c = '%' ]; then c='%%'; fi
shift
width=$1
shift
len=$(($# / 2 ))
if [ $len -lt 1 ]; then return; fi
#!width=$(tput cols)
width=$((width-2))
ignore=1
total=0
for val in "${@}"; do
if [ $ignore = 1 ]; then ignore=0
else ignore=1; total=$((total+val)); # echo "val=$val -> total=$total"
fi
done
#echo "total=$total width=$width"
# |================//////////..............|
# <- drawn_chars -><- new -> width
# drawn_val val total
# new = (width*(val+drawn_val))/total - drawn_chars
drawn_chars=0
drawn_val=0
printf "["
while [ "x${1}" != x ]; do
color=$1
shift
val=$1
shift
new=$(((width*(val+drawn_val))/total - drawn_chars))
if [ $new -eq 0 ]; then continue; fi
# echo
# echo "val=$val new=$new drawn_chars=$drawn_chars drawn_val=$drawn_val"
drawn_chars=$((drawn_chars+new))
drawn_val=$((drawn_val+val))
printf '\e[0;%sm' $color
eval "printf '$c%.0s' {1..${new}}"
done
printf "\e[0m]\n"
}
# WIDTH value value2 ...
nonColorBar() {
local c width len ignore val total color_index new
width=$1
shift
len=$#
if [ $len -lt 1 ]; then return; fi
#!width=$(tput cols)
width=$((width-2))
total=0
for val in "${@}"; do
total=$((total+val)) # echo "val=$val -> total=$total"
done
#echo "total=$total width=$width"
# |================//////////..............|
# <- drawn_chars -><- new -> width
# drawn_val val total
# new = (width*(val+drawn_val))/total - drawn_chars
drawn_chars=0
drawn_val=0
color_index=0
printf "["
while [ "x${1}" != x ]; do
c=${CHARS[$color_index]}
color_index=$((color_index+1))
if [ "$c" = '%' ]; then c='%%'; fi
val=$1
shift
new=$(((width*(val+drawn_val))/total - drawn_chars))
if [ $new -eq 0 ]; then continue; fi
drawn_chars=$((drawn_chars+new))
drawn_val=$((drawn_val+val))
#echo "new=$new; dc=$drawn_chars; dv=$drawn_val"
eval "printf '$c%.0s' {1..${new}}"
done
printf "]\n"
}
while read line; do
head=${line%%;*}
line=${line#*;}
hosts=${head#*:}
head=${line%%;*}
line=${line#*;}
state=${head#*:}
state=${state//\"/}
state=${state//\[/}
state=${state//\]/}
head=${line%%;*}
line=${line#*;}
user=${head#*:}
states["$state"]=${states["$state"]:-0}
users["$user"]=${users["$user"]:-0}
states["$state"]=$((${states["$state"]} + $hosts))
users["$user"]=$((${users["$user"]} + $hosts))
#echo "state=$state; keys => ${!states[@]}; values => ${states[@]}"
done < <(squeue --json | jq -r '.jobs[]| "hosts:" + (.node_count.number|tostring) + ";state:" + (.job_state|tostring) + ";user:" + .account +"/" + .user_name')
for i in RUNNING PENDING; do
states[$i]=${states[$i]:-0}
#echo "state=$i; keys => ${!states[@]}; values => ${states[@]}"
printf "%12s: %-${NUM_WIDTH}d\n" $i ${states[$i]}
unset states[$i]
done
for i in "${!states[@]}"; do
printf "%12s: %-${NUM_WIDTH}d\n" $i ${states[$i]}
done
#for i in "${!users[@]}"; do
# printf "%s: %3d " $i ${users[$i]}
#done
#printf "\n"
readarray NAMES < <(for i in "${!users[@]}"; do
printf "%s %s\n" $i ${users[$i]}
done | sort -rn -k2 | head -n $TOPUSERNUM)
USER_WIDTH=0
for i in ${NAMES[@]}; do
name=${i% *}
if [ ${USER_WIDTH} -lt ${#name} ]; then USER_WIDTH=${#name}; fi
done
for i in "${NAMES[@]}"; do
name=${i% *}
val=${i#* }
printf "%${USER_WIDTH}s %s\n" $name ${val}
done
declare -A allocated
declare -A idle
declare -A other
while read line; do
IFS='/' read -r -a fields <<< "$line"
if [ ${fields[4]} -ne 0 ]; then
allocated[${fields[0]}]=$((${fields[1]} + ${allocated[${fields[0]}]:-0}))
idle[${fields[0]}]=$((${fields[2]} + ${idle[${fields[0]}]:-0}))
other[${fields[0]}]=$((${fields[3]} + ${other[${fields[0]}]:-0}))
fi
done < <(sinfo --json | jq -r '.sinfo[]| "" + .partition.name + "/" + (.nodes.allocated| tostring) + "/" + ( .nodes.idle | tostring ) + "/" + ( .nodes.other | tostring ) +"/"+ ( .nodes.total | tostring
)')
width=$(tput cols)
if [ $USE_COLOR = 1 ]; then
width=$((width-$PART_WIDTH-3*$NUM_WIDTH-2))
printf "${C_ALLOC_H}%${PART_WIDTH}s %-${NUM_WIDTH}s${C_IDLE_H}%-${NUM_WIDTH}s${C_FAILED_H}%-${NUM_WIDTH}s\\e[m\n" Part Use Idl Flt
else
width=$((width-$PART_WIDTH-3*$NUM_WIDTH-10))
fi
for i in ${PARTS}; do
if [ $USE_COLOR = 1 ]; then
printf "%${PART_WIDTH}s ${C_ALLOC}%-${NUM_WIDTH}d${C_IDLE}%-${NUM_WIDTH}d${C_FAILED}%-${NUM_WIDTH}d\\e[m " "$i" ${allocated[$i]} ${idle[$i]} ${other[$i]}
colorBar "$CHAR" $width 3${C_A} ${allocated[$i]} 3${C_I} ${idle[$i]} 3${C_F} ${other[$i]}
else
printf "%${PART_WIDTH}s a:%-${NUM_WIDTH}d i:%-${NUM_WIDTH}d o:%-${NUM_WIDTH}d " "$i" ${allocated[$i]} ${idle[$i]} ${other[$i]}
nonColorBar $width ${allocated[$i]} ${idle[$i]} ${other[$i]}
fi
done