2010-10-18 12:49:41 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Plugin to graph cpu speed on FreeBSD
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
#
|
|
|
|
# sysctl - Override path to sysctl program
|
|
|
|
#
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
sysctl=${sysctl:-/sbin/sysctl}
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
if [ -x ${sysctl} ]; then
|
|
|
|
${sysctl} dev.cpu.0.freq 2>/dev/null | grep 'dev' >/dev/null 2>/dev/null
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "no (dev.cpu.0.freq not found)"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "no (sysctl binary not found)"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
echo 'graph_title CPU speed'
|
|
|
|
echo 'graph_args --base 1000 -l 0'
|
|
|
|
echo 'graph_vlabel speed in MHz'
|
|
|
|
echo 'graph_category system'
|
2010-11-04 10:50:42 +01:00
|
|
|
echo 'graph_scale no'
|
|
|
|
echo 'graph_info Current CPU speed in MHz. Available levels for the CPU:' `$sysctl -n dev.cpu.0.freq_levels|sed 's!/[0-9]*!!g;s! !, !g'` 'MHz'
|
2010-10-18 12:49:41 +02:00
|
|
|
|
|
|
|
echo cpu0.label cpu0
|
2010-11-04 10:50:42 +01:00
|
|
|
echo cpu0.info `$sysctl -n hw.model` Speed
|
2010-10-18 12:49:41 +02:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
file=/usr/local/var/munin/plugin-state/cpuspeed
|
|
|
|
|
|
|
|
echo -n "cpu0.value "
|
|
|
|
if find $file -mtime -300s 2>/dev/null|grep -Fq $file ; then
|
|
|
|
head -1 $file
|
|
|
|
else
|
|
|
|
$sysctl -n dev.cpu.0.freq
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get/cache cpuspeed "later".
|
|
|
|
export sysctl file
|
|
|
|
sh -c '(
|
|
|
|
rand=$(dd if=/dev/urandom bs=1 count=1 2>/dev/null|od -A n -D)
|
|
|
|
rand=$(expr $rand \* 60 / 256 + 25)
|
|
|
|
sleep $rand
|
|
|
|
$sysctl -n dev.cpu.0.freq > $file
|
|
|
|
)&' >/dev/null 2>&1
|