Mac MRTG: CPU Load
From TechMentor
<google uid="C01"></google> <hr\><br\>
Reporting Load Average
SNMP, on early versions of, OS X did not report CPU utilization so this was developed as one option to get the information. It reports the 1 minute and 5 minute load averages. This script was complemented with another (see below) that reported Total % busy and User % busy.
#!/bin/bash UPTIME=`uptime` echo "$UPTIME" | awk '{ a=NF-1; print $a*100; }' echo "$UPTIME" | awk '{ a=NF; print $a*100; }' echo "$UPTIME" | awk '{ gsub(/,/, ""); print $3, $4, $5; }' hostname
Reporting Percentage Busy
This seemed like a really silly hack, but turned out to work reasonably well. It runs top to retrieve the values. Using the 3rd sample seemed to be a good compromise in accuracy and performance. It reports total busy (usr + sys) and user busy.
#!/bin/bash USAGE=`top -l 3 | grep -e "CPU usage" | tail -1` USR=`echo "$USAGE" | awk '{ gsub(/%/, ""); print $8*100}'` SYS=`echo "$USAGE" | awk '{ gsub(/%/, ""); print $10*100}'` TOTAL=$(($SYS+$USR)) echo "$TOTAL" | awk '{print $1/100}' echo "$USR" | awk '{print $1/100}' #echo "$USAGE" | awk '{ gsub(/%/, ""); print $12}' uptime | awk '{ gsub(/,/, ""); print $3, $4, $5; }' hostname
<br\> <br\> <hr\> <google uid="C02"></google>