|
|
@@ -1,38 +1,40 @@
|
|
|
#!/bin/bash
|
|
|
|
|
|
# config
|
|
|
-max_usage=90
|
|
|
+max_usage=70
|
|
|
bar_width=50
|
|
|
-clear="\e[39m\e[0m"
|
|
|
+# colors
|
|
|
+white="\e[39m"
|
|
|
+green="\e[32m"
|
|
|
+red="\e[31m"
|
|
|
dim="\e[2m"
|
|
|
+undim="\e[0m"
|
|
|
|
|
|
-zpools=($(zpool list -Ho name | awk '{print $0}'))
|
|
|
+mapfile -t zpools < <(zpool list -Ho name,cap,size)
|
|
|
|
|
|
printf "\nzpool usage:\n"
|
|
|
|
|
|
-for zpool in "${zpools[@]}"
|
|
|
-do
|
|
|
+for line in "${zpools[@]}"; do
|
|
|
# get zpool usage
|
|
|
- line=$(zpool list -Ho name,cap,size "${zpool}")
|
|
|
usage=$(echo "$line" | awk '{print $2}' | sed 's/%//')
|
|
|
used_width=$((($usage*$bar_width)/100))
|
|
|
# color is green if usage < max_usage, else red
|
|
|
if [ "${usage}" -ge "${max_usage}" ]; then
|
|
|
- color="\e[31m"
|
|
|
+ color=$red
|
|
|
else
|
|
|
- color="\e[32m"
|
|
|
+ color=$green
|
|
|
fi
|
|
|
# print green/red bar until used_width
|
|
|
- bar="${color}"
|
|
|
- for sep in $(seq 1 $used_width); do
|
|
|
+ bar="[${color}"
|
|
|
+ for ((i=0; i<$used_width; i++)); do
|
|
|
bar+="="
|
|
|
done
|
|
|
# print dimmmed bar until end
|
|
|
- bar+="${clear}${dim}"
|
|
|
- for sep in $(seq 1 $(($bar_width-$used_width))); do
|
|
|
+ bar+="${white}${dim}"
|
|
|
+ for ((i=$used_width; i<$bar_width; i++)); do
|
|
|
bar+="="
|
|
|
done
|
|
|
- bar="[${bar}${clear}]"
|
|
|
+ bar+="${undim}]"
|
|
|
# print usage line & bar
|
|
|
echo "${line}" | awk '{ printf("%-10s%+3s used out of %+5s\n", $1, $2, $3); }' | sed -e 's/^/ /'
|
|
|
echo -e "${bar}" | sed -e 's/^/ /'
|