root / plugins / zfs / zpool_iostat @ aa9a39f0
Historique | Voir | Annoter | Télécharger (3,07 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
|
| 4 |
set -eu |
| 5 |
|
| 6 |
: <<=cut |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
zpool_iostat - Plugin to monitor transfer statistics of ZFS pools |
| 11 |
|
| 12 |
=head1 APPLICABLE SYSTEMS |
| 13 |
|
| 14 |
All systems with "zpool" installed. |
| 15 |
|
| 16 |
=head1 CONFIGURATION |
| 17 |
|
| 18 |
No configuration is required. |
| 19 |
|
| 20 |
=head1 INTERPRETATION |
| 21 |
|
| 22 |
This plugin shows a graph with read (positive) and write (negative) values |
| 23 |
for the IO transfer of each pool. |
| 24 |
|
| 25 |
=head1 MAGIC MARKERS |
| 26 |
|
| 27 |
#%# family=auto |
| 28 |
#%# capabilities=autoconf |
| 29 |
|
| 30 |
=head1 AUTHOR |
| 31 |
|
| 32 |
tsaavik <github@hellspark.com> |
| 33 |
Peter Doherty <peterd@acranox.org> |
| 34 |
Lars Kruse <devel@sumpfralle.de> |
| 35 |
|
| 36 |
=head1 LICENSE |
| 37 |
|
| 38 |
GPLv2 |
| 39 |
|
| 40 |
=cut |
| 41 |
|
| 42 |
|
| 43 |
# shellcheck source=/usr/share/munin/plugins/plugin.sh |
| 44 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 45 |
|
| 46 |
|
| 47 |
ZPOOL_BIN=/sbin/zpool |
| 48 |
ACTION="${1:-}"
|
| 49 |
|
| 50 |
|
| 51 |
if [ "$ACTION" = "autoconf" ]; then |
| 52 |
if [ -x "$ZPOOL_BIN" ]; then |
| 53 |
echo yes |
| 54 |
else |
| 55 |
echo "no (missing executable '$ZPOOL_BIN')" |
| 56 |
fi |
| 57 |
exit 0 |
| 58 |
fi |
| 59 |
|
| 60 |
zlines=$("$ZPOOL_BIN" iostat -v | wc -l | sed 's/ //g')
|
| 61 |
iostats=$("$ZPOOL_BIN" iostat -v 1 1 | tail "-$zlines")
|
| 62 |
zlist=$(echo "$iostats" \ |
| 63 |
| gawk '/alloc/ {next}; /avail/ {next}; /raid/ {next}; /mirror/ {next};
|
| 64 |
{ if ( $4 >=0 ) print $1}' \
|
| 65 |
| tr ' ' '\n') |
| 66 |
|
| 67 |
# Parse the n'th column of the iostat output for a given pool or disk as a |
| 68 |
# number (interpreting K and M suffixes). |
| 69 |
get_device_iostat_column() {
|
| 70 |
local device_label="$1" |
| 71 |
local stat_column="$2" |
| 72 |
# convert all numeric values into kB |
| 73 |
echo "$iostats" \ |
| 74 |
| gawk '{ if ($1 == "'"$device_label"'")
|
| 75 |
print $'"$stat_column"'; }' \ |
| 76 |
| gawk '/M/ {print strtonum($1)*1000};
|
| 77 |
/K/ {print strtonum($1)};
|
| 78 |
/[0-9]$/ {print int($1)/1000}'
|
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
get_device_fieldname() {
|
| 83 |
local device_id="$1" |
| 84 |
# Backwards compatibility (until 2016): keep the unprefixed pool name |
| 85 |
# for the fieldname, except for pool names starting with digits. |
| 86 |
if echo "$device_id" | grep -q "^[0-9]"; then |
| 87 |
clean_fieldname "_$device_id" |
| 88 |
else |
| 89 |
clean_fieldname "$device_id" |
| 90 |
fi |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
if [ "$ACTION" = "config" ]; then |
| 95 |
echo 'graph_title zpool iostat' |
| 96 |
echo 'graph_args --base 1000 -l 0' |
| 97 |
echo 'graph_vlabel write (-) / read (+) KBytes/s' |
| 98 |
echo 'graph_category disk' |
| 99 |
echo 'graph_scale no' |
| 100 |
echo 'graph_info This graph shows zpool iostat' |
| 101 |
# Assemble the "graph_order" as a sorted list of read/write pairs for |
| 102 |
# each device. |
| 103 |
printf "graph_order" |
| 104 |
echo "$zlist" | while read -r device_id; do |
| 105 |
fieldname="$(get_device_fieldname "pool_$device_id")" |
| 106 |
printf " %s_read %s_write" "$fieldname" "$fieldname" |
| 107 |
done |
| 108 |
# finalize the 'graph_order' with a newline |
| 109 |
echo |
| 110 |
# output all fields: write as negative numbers and read as positive |
| 111 |
echo "$zlist" | while read -r device_id; do |
| 112 |
fieldname="$(get_device_fieldname "pool_$device_id")" |
| 113 |
echo "${fieldname}_read.label $device_id"
|
| 114 |
echo "${fieldname}_read.type GAUGE"
|
| 115 |
echo "${fieldname}_read.graph no"
|
| 116 |
echo "${fieldname}_write.label $device_id"
|
| 117 |
echo "${fieldname}_write.type GAUGE"
|
| 118 |
echo "${fieldname}_write.negative ${fieldname}_read"
|
| 119 |
done |
| 120 |
exit 0 |
| 121 |
fi |
| 122 |
|
| 123 |
|
| 124 |
echo "$zlist" | while read -r device_id; do |
| 125 |
fieldname="$(get_device_fieldname "pool_$device_id")" |
| 126 |
echo "${fieldname}_read.value $(get_device_iostat_column "$device_id" 6)"
|
| 127 |
echo "${fieldname}_write.value $(get_device_iostat_column "$device_id" 7)"
|
| 128 |
done |
