#!/bin/sh # # Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # # 12-Aug-2015 @farrokhi # This script extracts IRQ interrupt rate for network interfaces from "vmstat -i" # on FreeBSD and feeds to munin # # XXX: This script relies on lang/gawk (we use extended regexp in awk). # # Magic markers: #%# family=auto #%# capabilities=autoconf suggest SCRIPT_NAME=$(basename $0) STAT_TYPE=`echo $SCRIPT_NAME | sed -n s/netirq_//p` VMSTAT="/usr/bin/vmstat" AWK=`which gawk` || ( echo "gawk not found"; exit 1 ) STATFILE=`mktemp -t netirq` ${VMSTAT} -i | sort -V > ${STATFILE} 2>/dev/null if [ $# -lt 1 ]; then if [ -z ${STAT_TYPE} ]; then echo "Should run from symlink" exit 1 fi elif [ "$1" == "suggest" ]; then for iface in `ifconfig -lu ether`; do echo ${iface} done elif [ "$1" == "autoconf" ]; then ${VMSTAT} -i >/dev/null 2>&1 && echo yes || echo no exit 0 elif [ "$1" == "config" ]; then if [ -z ${STAT_TYPE} ]; then echo "Should run from symlink"; exit 1 fi echo "graph_title IRQ Statistics for ${STAT_TYPE}" echo "graph_args --lower-limit 0 --base 1000" echo "graph_vlabel interrupts / second" echo "graph_category system" cat ${STATFILE} | ${AWK} ' BEGIN { FS = "[ ]{2,}" } /'${STAT_TYPE}'/ { split($1,name,":"); gsub(/ /,"", $1); print name[1]".label " $1; print name[1]".type DERIVE"; print name[1]".min 0"; print name[1]".draw LINE2"; } ' else ${AWK} ' { FS = "[ ]{2,}" } /'${STAT_TYPE}'/ { split($1,name,":"); print name[1]".value "$2 }' ${STATFILE} fi rm ${STATFILE}