82 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
		
		
			
		
	
	
			82 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
|  | #!/bin/sh | ||
|  | # | ||
|  | # Copyright (c) 2015 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 CPU and IRQ interrupt rates from "vmstat -i"  | ||
|  | # on FreeBSD and feeds to munin | ||
|  | # | ||
|  | # XXX: This script requires lang/gawk to be installed (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/intr_//p` | ||
|  | VMSTAT="/usr/bin/vmstat" | ||
|  | AWK=`which gawk` || exit 1 | ||
|  | 
 | ||
|  | 
 | ||
|  | STATFILE=`mktemp -t intr` | ||
|  | ${VMSTAT} -i | sort -V > ${STATFILE} 2>/dev/null | ||
|  | 
 | ||
|  | if [ $# -lt 1 ]; then | ||
|  | 
 | ||
|  | 
 | ||
|  |   case ${STAT_TYPE} in | ||
|  |     cpu) | ||
|  | 		cat ${STATFILE} | ${AWK} '{ FS = "[ ]{2,}" }  /^cpu/{split($1,name,":"); print name[1]".value "$2}' | ||
|  | 		;; | ||
|  |   esac  | ||
|  | 
 | ||
|  | 
 | ||
|  | elif [ "$1" == "suggest" ]; then    | ||
|  |    echo "cpu" | ||
|  | 
 | ||
|  | elif [ "$1" == "autoconf" ]; then | ||
|  |    ${VMSTAT} -i  >/dev/null 2>&1  && echo yes || echo no | ||
|  |    exit 0 | ||
|  | 
 | ||
|  | elif [ "$1" == "config" ]; then | ||
|  | 
 | ||
|  |   case ${STAT_TYPE} in | ||
|  |     cpu) | ||
|  | 		echo "graph_title CPU Timer Statistics" | ||
|  | 		echo "graph_args --lower-limit 0 --base 1000" | ||
|  | 		echo "graph_vlabel interrupts / second" | ||
|  | 		echo "graph_category system" | ||
|  | 		 | ||
|  | 		cat ${STATFILE} | ${AWK} '{ FS = "[ ]{2,}" }  /^cpu/{split($1,name,":"); print name[1]".label "$1"\n"name[1]".type DERIVE\n"name[1]".min 0"}' | ||
|  | 	;; | ||
|  |   esac | ||
|  | 
 | ||
|  | fi | ||
|  | 
 | ||
|  | rm ${STATFILE} | ||
|  | 
 |