#!/bin/sh
# -*- sh -*-
#
# $Id: df_abs.in 1589 2008-04-12 23:37:11Z matthias $
#
# Script to monitor absolute disk usage.
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
# Environment
#       exclude: space separated list if fs types to exclude.
#                iso9660 squashfs udf romfs ramfs by default
#       warning: Warning _percentage_, default 92
#       critical: Critical _percentage_, default 98
#
# Magic markers (optional - used by munin-config and installation
# scripts):
#
# $Id: df_abs.in 1589 2008-04-12 23:37:11Z matthias $
#
#%# family=manual
#%# capabilities=autoconf

. $MUNIN_LIBDIR/plugins/plugin.sh

if [ "$1" = "autoconf" ]; then
	echo yes
	exit 0
fi

exclude=${exclude:-iso9660 squashfs udf romfs ramfs}

exclude=$(echo $exclude | sed -e 's/ / -x /g' -e 's/^/-x /')

if [ "$1" = "config" ]; then

	echo 'graph_title Filesystem usage (in bytes)'
	echo 'graph_args --base 1024 --lower-limit 0'
	echo 'graph_vlabel bytes'
	echo 'graph_category disk'
	echo 'graph_total Total'
	df -P -l $exclude | sed 1d | grep -v "//" | 
	   while read dev size used avail cap mnt; do
	       name="$(clean_fieldname $dev)"
	       echo "$name.label $mnt"
	       echo "$name.cdef $name,1024,*"
	       echo "$name.warning $((size * ${warning:-92} / 100))"
	       echo "$name.critical $((size * ${critical:-98} / 100))"
	done
	exit 0
fi

df -P -l $exclude | sed 1d | grep -v "//" | 
   while read dev size used avail cap mnt; do
	echo "$(clean_fieldname $dev).value $used"
done
