#!/bin/sh
#
# Script to monitor disk usage.
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
#
#
# Magic markers (optional - used by munin-config and installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf

MAXLABEL=20

CELL=`basename $0 | sed 's/^afs_df_//g'`

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

clean_name() {
    echo $1 | sed 's/[\/.-]/_/g'
}


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

	echo 'graph_title '"$CELL"' partition usage (in %)'
	echo 'graph_args --upper-limit 100 -l 0'
	echo 'graph_vlabel %'
	echo 'graph_category AFS'
	echo 'graph_info This graph shows disk usage on the '"$CELL"' cell.'
	fs df /afs/"$CELL"/service/partitions/* | grep '^disk.' | while read i; do
	    name=`clean_name $i`
	    echo -n "$name.label "
	    echo $i | awk "{ print \$1; }"
	    echo "$name.warning 90"
	    echo "$name.critical 98"
	done
	exit 0
fi

fs df /afs/"$CELL"/service/partitions/* | grep '^disk.' | while read i; do
	name=`clean_name $i`
	echo -n "$name.value "
	echo $i | awk '{ print $3/$2*100 }'
done
