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
|
|
|
|
|
2016-12-04 15:57:59 +01:00
|
|
|
: <<=cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
zpool_iostat - Plugin to monitor transfer statistics of ZFS pools
|
|
|
|
|
|
|
|
=head1 APPLICABLE SYSTEMS
|
|
|
|
|
|
|
|
All systems with "zpool" installed.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
No configuration is required.
|
|
|
|
|
|
|
|
=head1 INTERPRETATION
|
|
|
|
|
|
|
|
This plugin shows a graph with read (positive) and write (negative) values
|
|
|
|
for the IO transfer of each pool.
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
tsaavik <github@hellspark.com>
|
|
|
|
Peter Doherty <peterd@acranox.org>
|
|
|
|
Lars Kruse <devel@sumpfralle.de>
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2016-12-04 15:56:32 +01:00
|
|
|
|
|
|
|
# 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')
|
2017-01-11 01:54:22 +01:00
|
|
|
iostats=$("$ZPOOL_BIN" iostat -v 1 1 | tail "-$zlines")
|
|
|
|
zlist=$(echo "$iostats" \
|
2018-06-13 05:01:04 +02:00
|
|
|
| awk '/alloc/ {next}; /avail/ {next}; /raid/ {next}; /mirror/ {next};
|
2017-01-11 01:54:22 +01:00
|
|
|
{ if ( $4 >=0 ) print $1}' \
|
|
|
|
| tr ' ' '\n')
|
|
|
|
|
|
|
|
# Parse the n'th column of the iostat output for a given pool or disk as a
|
|
|
|
# number (interpreting K and M suffixes).
|
|
|
|
get_device_iostat_column() {
|
|
|
|
local device_label="$1"
|
2016-12-04 15:47:29 +01:00
|
|
|
local stat_column="$2"
|
2017-01-11 01:54:22 +01:00
|
|
|
# convert all numeric values into kB
|
|
|
|
echo "$iostats" \
|
2018-06-13 05:01:04 +02:00
|
|
|
| awk '{ if ($1 == "'"$device_label"'") print $'"$stat_column"'; }' \
|
|
|
|
| awk '/M/ {print int($1)*1000};
|
|
|
|
/K/ {print int($1)};
|
2017-01-11 01:54:22 +01:00
|
|
|
/[0-9]$/ {print int($1)/1000}'
|
2016-12-04 15:47:29 +01:00
|
|
|
}
|
2011-01-23 00:07:49 +01:00
|
|
|
|
2017-01-11 01:54:22 +01:00
|
|
|
|
|
|
|
get_device_fieldname() {
|
|
|
|
local device_id="$1"
|
|
|
|
# Backwards compatibility (until 2016): keep the unprefixed pool name
|
|
|
|
# for the fieldname, except for pool names starting with digits.
|
|
|
|
if echo "$device_id" | grep -q "^[0-9]"; then
|
|
|
|
clean_fieldname "_$device_id"
|
2016-12-04 16:04:37 +01:00
|
|
|
else
|
2017-01-11 01:54:22 +01:00
|
|
|
clean_fieldname "$device_id"
|
2016-12-04 16:04:37 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-01-11 01:54:22 +01:00
|
|
|
|
2016-12-04 15:56:32 +01:00
|
|
|
if [ "$ACTION" = "config" ]; then
|
2016-12-04 16:05:42 +01:00
|
|
|
echo 'graph_title zpool iostat'
|
|
|
|
echo 'graph_args --base 1000 -l 0'
|
2017-01-11 01:54:22 +01:00
|
|
|
echo 'graph_vlabel write (-) / read (+) KBytes/s'
|
2016-12-04 16:05:42 +01:00
|
|
|
echo 'graph_category disk'
|
|
|
|
echo 'graph_scale no'
|
|
|
|
echo 'graph_info This graph shows zpool iostat'
|
2017-01-11 01:54:22 +01:00
|
|
|
# Assemble the "graph_order" as a sorted list of read/write pairs for
|
|
|
|
# each device.
|
2016-12-04 15:47:29 +01:00
|
|
|
printf "graph_order"
|
2017-01-11 01:54:22 +01:00
|
|
|
echo "$zlist" | while read -r device_id; do
|
2017-01-11 02:02:56 +01:00
|
|
|
fieldname="$(get_device_fieldname "$device_id")"
|
2016-12-04 15:47:29 +01:00
|
|
|
printf " %s_read %s_write" "$fieldname" "$fieldname"
|
|
|
|
done
|
2017-01-11 01:54:22 +01:00
|
|
|
# finalize the 'graph_order' with a newline
|
2016-12-04 15:47:29 +01:00
|
|
|
echo
|
|
|
|
# output all fields: write as negative numbers and read as positive
|
2017-01-11 01:54:22 +01:00
|
|
|
echo "$zlist" | while read -r device_id; do
|
2017-01-11 02:02:56 +01:00
|
|
|
fieldname="$(get_device_fieldname "$device_id")"
|
2017-01-11 01:54:22 +01:00
|
|
|
echo "${fieldname}_read.label $device_id"
|
2016-12-04 15:47:29 +01:00
|
|
|
echo "${fieldname}_read.type GAUGE"
|
|
|
|
echo "${fieldname}_read.graph no"
|
2017-01-11 01:54:22 +01:00
|
|
|
echo "${fieldname}_write.label $device_id"
|
2016-12-04 15:47:29 +01:00
|
|
|
echo "${fieldname}_write.type GAUGE"
|
|
|
|
echo "${fieldname}_write.negative ${fieldname}_read"
|
2016-12-04 16:05:42 +01:00
|
|
|
done
|
|
|
|
exit 0
|
2011-01-23 00:07:49 +01:00
|
|
|
fi
|
2017-01-11 01:54:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
echo "$zlist" | while read -r device_id; do
|
2017-01-11 02:02:56 +01:00
|
|
|
fieldname="$(get_device_fieldname "$device_id")"
|
2017-01-11 01:54:22 +01:00
|
|
|
echo "${fieldname}_read.value $(get_device_iostat_column "$device_id" 6)"
|
|
|
|
echo "${fieldname}_write.value $(get_device_iostat_column "$device_id" 7)"
|
2011-01-23 00:07:49 +01:00
|
|
|
done
|