From 253d8ebd1a852d69334ed7935b1438fb5c8ff00d Mon Sep 17 00:00:00 2001 From: Sec Date: Mon, 18 Oct 2010 12:49:41 +0200 Subject: [PATCH] Initial version --- plugins/other/cpuspeed_sane | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 plugins/other/cpuspeed_sane diff --git a/plugins/other/cpuspeed_sane b/plugins/other/cpuspeed_sane new file mode 100755 index 00000000..b169b5b3 --- /dev/null +++ b/plugins/other/cpuspeed_sane @@ -0,0 +1,59 @@ +#!/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' + echo 'graph_info This graph shows CPU speed.' + + echo cpu0.label cpu0 + echo cpu0.info CPU0 Speed + + 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