#!/bin/sh
#
# $OpenBSD: intr,v 1.1 2010/02/25 17:07:17 sthen Exp $
#
# Script to monitor interrupt activity on OpenBSD
#
# (c) 2010 Michael Knudsen <mk@openbsd.org>
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
# 	suggest  (optional - used by munin-config)
#

if [ "$1" = "autoconf" ]; then
	if [ "$(uname -s)" = "OpenBSD" ]; then
		echo yes
		exit 0
	else
		echo no
		exit 1
	fi
fi

if [ "$1" = "suggest" ]; then
	exit 0
fi

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

	echo 'graph_title Interrupt activity'
	echo 'graph_args --base 1000'
	echo 'graph_category system'
	echo 'graph_vlabel Interrupt count'

	vmstat -i | grep "^irq" | while read s; do
		name=$(echo $s | cut -d/ -f 2 | cut -f 1 | cut -d' ' -f 1)
		irq=$(echo $s | cut -d/ -f 1)
		echo $name'.label '$name' ('$irq')';
		echo $name'.type DERIVE';
		echo $name'.min 0';
	done
	exit 0
fi

vmstat -i | grep "^irq" | while read s; do
	name=$(echo $s | cut -d/ -f 2 | cut -f 1 | cut -d' ' -f 1)
	irq=$(echo $s | cut -d/ -f 1)
	val=$(echo $s | awk '{ print $2 }')
	echo $name'.value '$val;
done

