Skip to content

Instantly share code, notes, and snippets.

@ebirn
Created April 30, 2013 13:39
Show Gist options
  • Save ebirn/5488766 to your computer and use it in GitHub Desktop.
Save ebirn/5488766 to your computer and use it in GitHub Desktop.
simple nagios check that returns zfs usage by dataset and snapshots (recursively added for children),
<?php
#
# check_zfs: zfs usage check
# Erich Birbngruber <ebirn@outdated.at>
# twitter: @ebirn
#
$opt[1] = "--vertical-label \"Usage\" -b 1024 --title \"ZFS usage host backups\" -l 0 --rigid ";
$def[1] = "DEF:var1=$RRDFILE[1]:$DS[1]:AVERAGE " ;
$def[1] .= "DEF:var2=$RRDFILE[2]:$DS[2]:AVERAGE " ;
$def[1] .= "CDEF:total=var1,var2,+ " ;
$def[1] .= "AREA:var1#2222ff:\"data\" " ;
$def[1] .= "GPRINT:var1:LAST:\"%7.2lf %Sb curr\" " ;
$def[1] .= "GPRINT:var1:AVERAGE:\"%7.2lf %Sb avg\" " ;
$def[1] .= "GPRINT:var1:MAX:\"%7.2lf %Sb max\\n\" " ;
$def[1] .= "AREA:var2#aaaaaa:\"snapshots\":STACK " ;
$def[1] .= "GPRINT:var2:LAST:\"%7.2lf %Sb curr\" " ;
$def[1] .= "GPRINT:var2:AVERAGE:\"%7.2lf %Sb avg\" " ;
$def[1] .= "GPRINT:var2:MAX:\"%7.2lf %Sb max\\n\" ";
$def[1] .= "LINE1:total#000000:\"total\" " ;
$def[1] .= "GPRINT:total:LAST:\"%7.2lf %Sb last\" ";
$def[1] .= "GPRINT:total:AVERAGE:\"%7.2lf %Sb avg\" ";
$def[1] .= "GPRINT:total:MAX:\"%7.2lf %Sb max\" ";
?>
#!/bin/sh
#
# original idea: http://www.googlux.com/nagios.plugin.zfs.usage.html
#
# check_zfs: zfs usage check
# Erich Birbngruber <ebirn@outdated.at>
# twitter: @ebirn
#
# ------ Nagios plugin return values
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
ZFS="sudo zfs"
# -------- get dataset of filesystem
DATASETS=$($ZFS list -r -H $1 | awk '{NR>1} {print $1}')
for DATASET in $DATASETS; do
for i in usedbydataset usedbychildren usedbysnapshots;
do
if [ "`$ZFS get -Hp ${i} ${DATASET} | awk '{print $3}'`" = "-" ]; then
echo "Somehow $ZFS property ${i} cannot be determined"
exit 3
fi
done
#CHILDRENUSE=`$ZFS get -Hp usedbychildren ${DATASET} | awk '{print $3}'`
DATA=$(( $DATA + `$ZFS get -Hp usedbydataset ${DATASET} | awk '{print $3}'`))
SNAPSHOT=$(( $SNAPSHOT + `$ZFS get -Hp usedbysnapshots ${DATASET} | awk '{print $3}'`))
done
DATAMB=$(( $DATA/1024/1024 ))
SNAPSHOTMB=$(( $SNAPSHOT/1024/1024 ))
#echo "dataset: $1"
#echo "children: $CHILDRENUSE data: $DATA snaps: $SNAPSHOT"
echo "ZFS OK used space: data: $DATAMB MB, snapshots: $SNAPSHOTMB MB|data=$DATA;snapshot=$SNAPSHOT"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment