#!/bin/sh # #NADDS Agent - http://nadds.drmadcow.net/ #Single CPU Load Detection Agent (Linux) #Agent Author: Daryl Quenet #Date: 2003-Apr-16 (V1.0) . /usr/local/bcnu/etc/bcnuenv . $BCNUHOME/agent/agent_head OUTFILE=$BCNUTMP/${BCNUAGENT}.out TMPFILE=$BCNUTMP/${BCNUAGENT}.tmp rm -f $OUTFILE $TMPFILE for param in $BCNUPARAM do bcnu_param interval=$p1 count=$p2 avewarning=$p3 aveerror=$p4 done count=`echo $count+1| bc -l` iostat -c $interval $count >$TMPFILE count=`echo $count-1| bc -l` idletotal=`cat $TMPFILE|sed '1,4d'|awk 'NF==4{print $4} NF==5{print $5}'|grep '[0-9]'|xargs|sed 's/ /+/g'|bc -l` total=`echo 100*$count-$idletotal|bc -l` avecpu=`echo $total / $count|bc -l|awk '{printf "%3.2f", $1}'` cpulev=`echo $avecpu|sed 's/\.[0-9]*//'` printf "CPU Usuage Information:\n\n" >$OUTFILE printf "Average CPU usuage at $avecpu percent\n" >>$OUTFILE printf "CPU usuage sampled every $interval seconds for $count iterations.\n\n" >>$OUTFILE cat $TMPFILE|sed '3,5d' >>$OUTFILE if [ $cpulev -ge $aveerror ]; then BCNUMSG="$BCNU -m 'error - cpu average usage at $avecpu percent' -f $OUTFILE -e $BCNU_ERR -t $BCNUHOSTTYPE $BCNUHOST" bcnu_err_send elif [ $cpulev -ge $avewarning ]; then BCNUMSG="$BCNU -m 'warning - cpu average usuage at $avecpu percent' -f $OUTFILE -e $BCNU_WARN -t $BCNUHOSTTYPE $BCNUHOST" bcnu_warn_send else BCNUMSG="$BCNU -m 'ok - cpu average usuage at $avecpu percent' -f $OUTFILE -e $BCNU_OK -t $BCNUHOSTTYPE $BCNUHOST" bcnu_send fi