diff --git a/plugins/system/multicpu1sec/multicpu1sec b/plugins/system/multicpu1sec/multicpu1sec new file mode 100644 index 00000000..1387b896 --- /dev/null +++ b/plugins/system/multicpu1sec/multicpu1sec @@ -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. + \ No newline at end of file diff --git a/plugins/system/multicpu1sec/multicpu1sec-days.png b/plugins/system/multicpu1sec/multicpu1sec-days.png new file mode 100644 index 00000000..206a541b Binary files /dev/null and b/plugins/system/multicpu1sec/multicpu1sec-days.png differ diff --git a/plugins/system/multicpu1sec/multicpu1sec-hours.png b/plugins/system/multicpu1sec/multicpu1sec-hours.png new file mode 100644 index 00000000..362f6188 Binary files /dev/null and b/plugins/system/multicpu1sec/multicpu1sec-hours.png differ diff --git a/plugins/system/multicpu1sec/multicpu1sec-minutes.png b/plugins/system/multicpu1sec/multicpu1sec-minutes.png new file mode 100644 index 00000000..da793bfc Binary files /dev/null and b/plugins/system/multicpu1sec/multicpu1sec-minutes.png differ