1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

[zpool_iostat] use 'clean_fieldname' and separate function 'get_pool_iostat'

FIeldnames possibly started with a digit before.
Closes: #779
This commit is contained in:
Lars Kruse 2016-12-04 15:47:29 +01:00
parent 9640be3646
commit 3e86f2b80a

View file

@ -1,7 +1,10 @@
#!/bin/sh #!/bin/sh
. "$MUNIN_LIBDIR/plugins/plugin.sh"
ZPOOL_BIN=/sbin/zpool ZPOOL_BIN=/sbin/zpool
if [ "$1" = "autoconf" ]; then if [ "$1" = "autoconf" ]; then
if [ -x "$ZPOOL_BIN" ]; then if [ -x "$ZPOOL_BIN" ]; then
echo yes echo yes
@ -13,9 +16,16 @@ fi
zlines=$("$ZPOOL_BIN" iostat -v | wc -l | sed 's/ //g') zlines=$("$ZPOOL_BIN" iostat -v | wc -l | sed 's/ //g')
pool_iostat=$("$ZPOOL_BIN" iostat -v 1 1 | tail "-$zlines") pool_iostat=$("$ZPOOL_BIN" iostat -v 1 1 | tail "-$zlines")
zlist=$(echo "$pool_iostat" | gawk '/alloc/ {next}; /avail/ {next}; /raid/ {next}; /mirror/ {next}; { if ( $4 >=0 ) print $1}') zlist=$(echo "$pool_iostat" | gawk '/alloc/ {next}; /avail/ {next}; /raid/ {next}; /mirror/ {next}; { if ( $4 >=0 ) print $1}' | tr ' ' '\n')
zname=$(echo "$pool_iostat" | gawk '/alloc/ {next}; /avail/ {next}; /raid/ {next}; /mirror/ {next}; { if ( $4 >=0 ) print $1}' | gawk '{gsub("[^a-zA-Z0-9_]", "_", $1); print}')
zorder=$(for o in $zname; do echo "${o}_read "; echo "${o}_write "; done) # parse the n'th column of the iostat output for a given pool as a number (interpreting K and M suffixes)
get_pool_iostat() {
local pool_label="$1"
local stat_column="$2"
echo "$pool_iostat" \
| gawk '{ if ($1 == "'"$pool_label"'") print $'"$stat_column"'; }' \
| gawk '/M/ {print strtonum($1)*1000}; /K/ {print strtonum($1)}; /[0-9]$/ {print int($1)/1000}'
}
if [ "$1" = "config" ]; then if [ "$1" = "config" ]; then
echo 'graph_title zpool iostat' echo 'graph_title zpool iostat'
@ -24,27 +34,28 @@ if [ "$1" = "config" ]; then
echo 'graph_category fs' echo 'graph_category fs'
echo 'graph_scale no' echo 'graph_scale no'
echo 'graph_info This graph shows zpool iostat' echo 'graph_info This graph shows zpool iostat'
echo "graph_order $zorder" # assemble the "graph_order" as a sorted list of read/write pairs for each poll
echo "$zlist" | tr ' ' '\n' | while read -r i; do printf "graph_order"
case "$i" in echo "$zlist" | while read -r pool_id; do
*) name=$(echo "$i" | gawk '{ gsub("[^a-zA-Z0-9_]", "_", $1); print }') ;; fieldname="$(clean_fieldname "pool_$pool_id")"
esac printf " %s_read %s_write" "$fieldname" "$fieldname"
echo "${name}_read.label $i" done
echo "${name}_read.type GAUGE" # finalize the 'graph_order'
echo "${name}_read.graph no" echo
echo "${name}_write.label $i" # output all fields: write as negative numbers and read as positive
echo "${name}_write.type GAUGE" echo "$zlist" | while read -r pool_id; do
echo "${name}_write.negative ${name}_read" fieldname="$(clean_fieldname "pool_$pool_id")"
echo "${fieldname}_read.label $pool_id"
echo "${fieldname}_read.type GAUGE"
echo "${fieldname}_read.graph no"
echo "${fieldname}_write.label $pool_id"
echo "${fieldname}_write.type GAUGE"
echo "${fieldname}_write.negative ${fieldname}_read"
done done
exit 0 exit 0
fi fi
echo "$zlist" | tr ' ' '\n' | while read -r iz; do echo "$zlist" | while read -r pool_id; do
zlabel=$(echo "$iz" | gawk '{print $1}') fieldname="$(clean_fieldname "pool_$pool_id")"
case "$iz" in echo "${fieldname}_read.value $(get_pool_iostat "$pool_id" 6)"
*) name=$(echo "$iz" | gawk '{ gsub("[^a-zA-Z0-9_]", "_", $1); print $1 }') ;; echo "${fieldname}_write.value $(get_pool_iostat "$pool_id" 7)"
esac
echo -n "${name}_read.value "
echo "$pool_iostat" | gawk '{ if ($1 == "'"$zlabel"'") print $6; }' | gawk '/M/ {print strtonum($1)*1000}; /K/ {print strtonum($1)}; /[0-9]$/ {print int($1)/1000}'
echo -n "${name}_write.value "
echo "$pool_iostat" | gawk '{ if ($1 == "'"$zlabel"'") print $7; }' |gawk '/M/ {print strtonum($1)*1000}; /K/ {print strtonum($1)}; /[0-9]$/ {print int($1)/1000}'
done done