2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/processes/cpuutil

74 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/bin/sh
2008-12-21 12:33:15 +01:00
# See /usr/include/sys/dk.h !
PATH=/usr/bin:/usr/sbin:/sbin
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
#ADBINPUT="./vmunix ."
ADBINPUT="/stand/vmunix /dev/kmem"
NMPINFO=$( /bin/echo "nmpinfo/D" | \
/bin/adb -o $ADBINPUT 2>/dev/null | \
/bin/sed '/^nmpinfo: *[0-9]/!d;s/^[^:]*://' )
echo_func () {
echo ${1}.label $2
echo ${1}.draw $3
echo ${1}.type DERIVE
echo ${1}.min 0
echo ${1}.cdef ${1},$NMPINFO,/
}
if [ "$1" = "config" ]; then
echo 'graph_title CPU usage graph based on kernel counters'
echo 'graph_order sys user wio idle'
# graphmax=$(( $NMPINFO * 100 ))
graphmax=100
echo "graph_args -r -l 0 --upper-limit $graphmax"
echo 'graph_vlabel %'
echo 'graph_category processes'
echo 'graph_scale no'
echo 'graph_info This graph shows how CPU time is spent.'
echo_func sys system AREA
echo "sys.info CPU time spent in running the kernel code"
echo_func user user STACK
echo 'user.info CPU time spent by tunning application code'
echo_func wio iowait STACK
echo 'wio.info CPU idle time in waiting IO (disk)'
echo_func idle idle STACK
echo 'idle.info Idle CPU time'
exit 0
fi
CPU=0
MAXCPU=$(( $NMPINFO * 72 ))
ADBCMD="0d200\$w"
while [ $CPU -lt $MAXCPU ]; do
ADBCMD="${ADBCMD}\nmcp_time+0d${CPU}/18D"
CPU=$(( $CPU + 72 ))
done
/bin/echo "${ADBCMD}\n\$q" | /bin/adb -o $ADBINPUT 2>/dev/null | \
/bin/sed '/^mcp_time.*:.*[0-9]/!d;s/^[^:]*://' | /bin/awk \
'{ \
uh += $1 ; nh += $3 ; sh += $5 ; ih += $7 ; wh += $9 ; \
ul += $2 ; nl += $4 ; sl += $6 ; il += $8 ; wl += $10 ; \
} END { \
GIGA = 4294967296 ; \
printf( "sys.value %0.f\n", sh * GIGA + sl ) ; \
printf( "user.value %0.f\n", ( uh + nh ) * GIGA + ul + nl ) ; \
printf( "wio.value %0.f\n", wh * GIGA + wl ) ; \
printf( "idle.value %0.f\n", ih * GIGA + il ) ; \
}'