2016-12-04 15:12:59 +01:00
|
|
|
#!/bin/sh
|
2016-12-04 15:56:32 +01:00
|
|
|
# -*- sh -*-
|
2011-03-23 23:44:38 +01:00
|
|
|
|
2016-12-04 15:56:32 +01:00
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
|
|
# shellcheck source=/usr/share/munin/plugins/plugin.sh
|
2016-12-04 15:47:29 +01:00
|
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
|
|
|
|
2016-12-04 15:56:32 +01:00
|
|
|
|
2016-12-04 15:24:03 +01:00
|
|
|
ZPOOL_BIN=/sbin/zpool
|
2016-12-04 15:56:32 +01:00
|
|
|
ACTION="${1:-}"
|
2016-12-04 15:24:03 +01:00
|
|
|
|
2016-12-04 15:47:29 +01:00
|
|
|
|
2016-12-04 15:56:32 +01:00
|
|
|
if [ "$ACTION" = "autoconf" ]; then
|
2016-12-04 15:24:03 +01:00
|
|
|
if [ -x "$ZPOOL_BIN" ]; then
|
|
|
|
echo yes
|
|
|
|
else
|
|
|
|
echo "no (missing executable '$ZPOOL_BIN')"
|
|
|
|
fi
|
|
|
|
exit 0
|
2011-03-23 23:44:38 +01:00
|
|
|
fi
|
2011-01-23 00:07:49 +01:00
|
|
|
|
2016-12-04 15:24:03 +01:00
|
|
|
zlines=$("$ZPOOL_BIN" iostat -v | wc -l | sed 's/ //g')
|
2016-12-04 15:27:05 +01:00
|
|
|
pool_iostat=$("$ZPOOL_BIN" iostat -v 1 1 | tail "-$zlines")
|
2016-12-04 15:47:29 +01:00
|
|
|
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}'
|
|
|
|
}
|
2011-01-23 00:07:49 +01:00
|
|
|
|
2016-12-04 15:56:32 +01:00
|
|
|
if [ "$ACTION" = "config" ]; then
|
2011-01-23 00:07:49 +01:00
|
|
|
echo 'graph_title zpool iostat'
|
|
|
|
echo 'graph_args --base 1000 -l 0'
|
|
|
|
echo 'graph_vlabel write - read KBytes/s'
|
2017-02-21 22:15:07 +01:00
|
|
|
echo 'graph_category fs'
|
2011-01-23 00:07:49 +01:00
|
|
|
echo 'graph_scale no'
|
|
|
|
echo 'graph_info This graph shows zpool iostat'
|
2016-12-04 15:47:29 +01:00
|
|
|
# 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"
|
2011-01-23 00:07:49 +01:00
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
2016-12-04 15:47:29 +01:00
|
|
|
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)"
|
2011-01-23 00:07:49 +01:00
|
|
|
done
|