mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
69 lines
2.1 KiB
Bash
Executable File
69 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# -*- sh -*-
|
|
|
|
set -eu
|
|
|
|
|
|
# shellcheck source=/usr/share/munin/plugins/plugin.sh
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
|
|
|
|
|
ZPOOL_BIN=/sbin/zpool
|
|
ACTION="${1:-}"
|
|
|
|
|
|
if [ "$ACTION" = "autoconf" ]; then
|
|
if [ -x "$ZPOOL_BIN" ]; then
|
|
echo yes
|
|
else
|
|
echo "no (missing executable '$ZPOOL_BIN')"
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
zlines=$("$ZPOOL_BIN" iostat -v | wc -l | sed 's/ //g')
|
|
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}' | tr ' ' '\n')
|
|
|
|
# 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 [ "$ACTION" = "config" ]; then
|
|
echo 'graph_title zpool iostat'
|
|
echo 'graph_args --base 1000 -l 0'
|
|
echo 'graph_vlabel write - read KBytes/s'
|
|
echo 'graph_category fs'
|
|
echo 'graph_scale no'
|
|
echo 'graph_info This graph shows zpool iostat'
|
|
# assemble the "graph_order" as a sorted list of read/write pairs for each poll
|
|
printf "graph_order"
|
|
echo "$zlist" | while read -r pool_id; do
|
|
fieldname="$(clean_fieldname "pool_$pool_id")"
|
|
printf " %s_read %s_write" "$fieldname" "$fieldname"
|
|
done
|
|
# finalize the 'graph_order'
|
|
echo
|
|
# output all fields: write as negative numbers and read as positive
|
|
echo "$zlist" | while read -r pool_id; do
|
|
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
|
|
exit 0
|
|
fi
|
|
echo "$zlist" | while read -r pool_id; do
|
|
fieldname="$(clean_fieldname "pool_$pool_id")"
|
|
echo "${fieldname}_read.value $(get_pool_iostat "$pool_id" 6)"
|
|
echo "${fieldname}_write.value $(get_pool_iostat "$pool_id" 7)"
|
|
done
|