# !/bin/sh
#
# Plugin to monitor the individual interrupt sources.
#
# Usage: Link or copy into /etc/munin/node.d/
#
# $Log: irqstats.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.
#
#
#
# Magic markers (optional - only used by munin-config and some
# installation scripts):
#
#%# family=auto
#%# capabilities=autoconf

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

intr_sources () {
    /usr/bin/vmstat -i | awk '
/^interrupt/ { next; }
/^Total/ { next; }
{
    s=substr($0, 1, 24);
    gsub(" *$", "", s);
    gsub(" ", "_", s);
    print s;
}
'
}

# If run with the "config"-parameter, give out information on how the
# graphs should look.

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

    echo 'graph_title Individual interrupts'
    echo 'graph_args --base 1000 -l 0'
    echo 'graph_vlabel interrupts / ${graph_period}'
    echo 'graph_category system'
    echo -n 'graph_order '
    for i in `intr_sources`; do
	echo -n ' intr_'${i}
    done
    echo

    for i in `intr_sources`; do
#	echo 'intr_'${i}'.draw LINE'
	echo 'intr_'${i}'.label' `echo $i | sed -e 's/_/ /g'`
	echo 'intr_'${i}'.info Interrupt' `echo $i | sed -e 's/_/ /g'`
	echo 'intr_'${i}'.type DERIVE'
	echo 'intr_'${i}'.min 0'
    done
    exit 0
fi

/usr/bin/vmstat -i | awk '
/^interrupt/ { next; }
/^Total/ { next; }
/[0-9]/{
    s=substr($0, 1, 24);
    gsub(" *$", "", s);
    gsub(" ", "_", s);
    print "intr_" s ".value " $(NF-1);
}
'
