#!/bin/sh

# Configuration variables
#
#   fs_df  - path to df executable (GNU df makes life easier)
#
#%# family=manual

DF=${fs_df:-/usr/bin/df}
TAIL=/usr/bin/tail

if $DF -P -l -i >/dev/null 2>&1; then
	DF="$DF -P -l -i"
	FSNAME=6
	PCNT=5
else
	DF="$DF -oi 2>/dev/null"
	FSNAME=5
	PCNT=4
fi

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

        echo 'graph_title Filesystem inode usage (in %)'
        echo 'graph_args --upper-limit 100'
		echo 'graph_category disk'
        eval $DF | $TAIL +2 | while read i; do
                name=`echo $i | sed 's/[\/.]/_/g' | awk '{ print $1 }'`
		# Ignore tmpfs.
		if [ "$name" != "swap" ]; then
			printf "$name.label "
			echo $i | awk '{ print $'$FSNAME' }'
			printf "$name.warn "
			echo 95
		fi
        done
        exit 0
fi

eval $DF | $TAIL +2 | while read i; do
        name=`echo $i | sed 's/[\/.]/_/g' | awk '{ print $1 }'`
	# Ignore tmpfs.
	if [ "$name" != "swap" ]; then
		printf "$name.value "
		echo $i | awk '{ p=$'$PCNT'; i=index(p, "%"); print substr(p, 1, i-1) }'
	fi
done
