Monitoring average CPUspeed on Systems with dynamic CPUspeed

Andreas Pfaffeneder apfaffeneder at zuhause-local.de
Sun Dec 30 23:35:30 CET 2007


Hi folks,

to monitor the 5 minute average cpu-speed of your notebook or server
capable of changing its cpu speed you can use the folling bits:

CLIENT:
Place cpuspeed.sh in the clients ext-directory:
cpuspeed.sh (requires bash, awk and loaded cpufreq_stats.ko)
#!/bin/bash
COLUMN=cpuspeed # Name of the column
COLOR=green          # By default, everything is OK
MSG=""
STATEFILE="/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state"
SPEEDS=`awk '{print $1}' $STATEFILE`
for SPEED in $SPEEDS; do
        export TICKS$SPEED=`grep $SPEED $STATEFILE | awk '{print $2}'`
done
sleep 300
for SPEED in $SPEEDS; do
        export TICKS${SPEED}_2=`grep $SPEED $STATEFILE|awk '{print $2}'`
done
for SPEED in $SPEEDS; do
        DIFF=$[TICKS${SPEED}_2 - TICKS$SPEED]
        DIFFSUM=$[$DIFFSUM + $DIFF ]
        if [ $DIFF -gt 0 ]; then
        CLOCKS=$[$CLOCKS + ($DIFF*$SPEED) ]
        fi
done
RESULT=$[$CLOCKS/$DIFFSUM/1000]
MSG="Mhz:$RESULT"
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
"
exit 0
/cpuspeed.sh

Add to clientlaunch.cfg:
[cpuspeed]
        ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg
        CMD $HOBBITCLIENTHOME/ext/cpuspeed.sh
        INTERVAL 5m


SERVER:
Add the following lines to hobbitgraph.cfg:
[cpuspeed]
        TITLE CPU Speed
        YAXIS Mhz
        DEF:speed=cpuspeed.rrd:Mhz:AVERAGE
        LINE2:speed#000000:AVERAGE
        GPRINT:speed:LAST: \: %5.1lf (cur)
        GPRINT:speed:MAX: \: %5.1lf (max)
        GPRINT:speed:MIN: \: %5.1lf (min)
        GPRINT:speed:AVERAGE: \: %5.1lf (avg)\n

Modify/Add hobbitserver.cfg:
TEST2RRD: Add cpuspeed=ncv
Add line: NCV_cpuspeed="Mhz:GAUGE"
Optional: Add cpuspeed to line GRAPHS

The cpuspeed.sh could easily be extended to get values per CPU, but I
have not seen CPUs changing their speeds independently so far.

Andreas



More information about the Xymon mailing list