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

Adding multicpu1sec from http://plugins.munin-monitoring.org/ as it serves as an example for 1 sec granularity.

This commit is contained in:
Steve Schnepp 2012-01-16 16:03:15 +01:00
parent e5710781fd
commit 8a95538509
4 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,95 @@
#!/bin/bash
#%# family=auto
#%# capabilities=autoconf
interval=1 # mpstat sampling interval
timeout=1200 # 20 minutes daemon watchdog timeout
watchdog=60 # test for timeout every $watchdog seconds
pluginfull="$0" # full name of plugin
plugin="${0##*/}" # name of plugin
pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid"
cache="$MUNIN_PLUGSTATE/munin.$plugin.value"
graph="$plugin"
section="system:cpu"
style="AREA"
cpus=$(grep -c ^processor /proc/cpuinfo)
run_watchdog() { # should also trap kill and term signals
while :; do
sleep ${watchdog:-600}
touch -d now-${timeout:-1200}sec $cache
[ $pidfile -nt $cache ] || break
done
[ -f $pidfile ] || exit # may have been removed by terminating daemon
kill $(cat $pidfile)
rm -f $pidfile $cache
}
run_acquire() {
echo "$$" > $pidfile
$pluginfull watchdog &
mpstat -P ALL $interval |
awk -v cpus=$cpus '$2>=0&&$2<10 {print $2, systime(), (100-$11)/cpus}' >> $cache
rm -f $pidfile $cache
}
run_daemon() {
if [ -f $pidfile ]; then
touch $pidfile
else
$pluginfull acquire &
fi
}
# --------------------------------------------------------------------------
run_autoconf() {
run=(yes no)
type -t mpstat > /dev/null
echo "${run[$?]}"
}
run_config() {
run_daemon
cat << EOF
graph_title $graph
graph_category $section
graph_vlabel average cpu use %
graph_scale no
graph_total All CPUs
update_rate 1
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y
EOF
cpun=0
for ((i=0; i<$cpus; i++)); do
cat << EOF
cpu${cpun}.label CPU $cpun
cpu${cpun}.draw $style
cpu${cpun}.min 0
EOF
style=STACK
((cpun++))
done
}
run_fetch() {
run_daemon
awk 'NF==3 {print "cpu" $1 ".value " $2 ":" $3}' $cache
> $cache
}
run_${1:-fetch}
exit 0
# export -f functionname export functionname to subshell, avoiding the need
# for locating plugin for subshell calling, when process needs a different
# pid. Instead, $SHELL -c functionname can be used. useful for calling
# acquire which needs a different pid than watchdog, otherwise watchdog
# could/will kill itself when expiring before the watched process is killed.
# not a POSIX feature.

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB