#!/bin/sh
#
# Plugin to monitor NFS server traffic
#
# $Log: nfsd.in,v $
# Revision 1.1.1.1  2006/06/04 20:53:57  he
# Import the client version of the Munin system monitoring/graphing
# tool -- project homepage is at http://munin.sourceforge.net/
#
# This package has added support for NetBSD, via a number of new plugin
# scripts where specific steps needs to be taken to collect information.
#
# I also modified the ntp_ plugin script to make it possible to not
# plot the NTP poll delay, leaving just jitter and offset, which IMO
# produces a more telling graph.
#
#
#
#%# family=auto
#%# capabilities=autoconf


getnames () {
    /usr/bin/nfsstat -s | awk '
/RPC Counts/ { coll = 1; next; }
/Server Errors/ { exit 0; }
/[a-z]/ && coll {
    for (n = 1; n <= NF; n++) {
	print $n
    }
}
'
}

if [ "$1" = "autoconf" ]; then
    if [ -x /usr/bin/nfsstat ]; then
	echo yes
	exit 0
    else
	echo no
	exit 0
    fi
fi

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

    echo 'graph_title NFS Server'
    echo 'graph_args --base 1000 -l 0'
    echo 'graph_vlabel requests / ${graph_period}'
    echo 'graph_total total'
    echo 'graph_category NFS'
    for a in `getnames` ; do
	echo "$a.label $a"
	echo "$a.type DERIVE"
	echo "$a.min 0"
    done
    exit 0
fi

/usr/bin/nfsstat -s | awk '
/RPC Counts/ { coll=1; next; }
/Server Errors/ { exit 0; }
/[a-z]/ && coll {
    for (n in names) {
	names[n] = ""
    }
    for (n = 1; n <= NF; n++) {
	names[n] = $n
    }
}
/[0-9]/ && coll {
    for (n = 1; n <= NF/2; n++) {
	name = names[n]
	values[name] = $((n - 1) * 2 + 1)
    }
}
END {
    for (v in values) {
	print v ".value " values[v];
    }
}
'
