From 5ff3522eccc5241167cadc30f3212f7983c733aa Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Mon, 18 Jul 2016 17:30:39 +0200 Subject: [PATCH] if1sec_: implement autostart, be more like if_ * look for already running acquire process, or start one * use CDEF to return bits/second (like if_) * increase lifetime to 450 days (like if_) * changed category to plain "network" (like if_) * report max interface speed (like if_) * small performance improvement: don't fork two cat(1) and one date(1) every second (this roughly halves the CPU time used on my system) --- plugins/network/if1sec_ | 100 +++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 31 deletions(-) diff --git a/plugins/network/if1sec_ b/plugins/network/if1sec_ index 28b45ec7..1414fa3b 100755 --- a/plugins/network/if1sec_ +++ b/plugins/network/if1sec_ @@ -1,15 +1,11 @@ #! /bin/sh -# Currently the plugin does *not* autostart -# -# It has to be launched via rc.d : -# munin-run if1sec_eth0 acquire -pluginfull="$0" # full name of plugin -plugin="${0##*/}" # name of plugin +pluginfull="$0" # full name of plugin +plugin="${0##*/}" # name of plugin pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid" cache="$MUNIN_PLUGSTATE/munin.$plugin.value" -IFACE="${0##*/if1sec_}" # interface +IFACE="${0##*/if1sec_}" # interface if [ ! -r "/sys/class/net/$IFACE/statistics/tx_bytes" ] then @@ -19,44 +15,86 @@ fi if [ "$1" = "acquire" ] then - ( - while sleep 1 - do - echo $( - date +%s - cat /sys/class/net/$IFACE/statistics/tx_bytes - cat /sys/class/net/$IFACE/statistics/rx_bytes - ) - done | awk "{ - print \"${IFACE}_tx.value \" \$1 \":\" \$2; - print \"${IFACE}_rx.value \" \$1 \":\" \$3; - system(\"\"); - }" >> $cache - ) & - echo $! > $pidfile - exit 0 + ( + exec <&- >&- 2>&- + while sleep 1 + do + read tx < /sys/class/net/$IFACE/statistics/tx_bytes + read rx < /sys/class/net/$IFACE/statistics/rx_bytes + echo "$tx $rx" + done | awk "{ + now = systime() + print \"${IFACE}_tx.value \" now \":\" \$1 + print \"${IFACE}_rx.value \" now \":\" \$2 + system(\"\") + }" >> $cache + ) & + echo $! > $pidfile + exit 0 fi if [ "$1" = "config" ] then - cat < ${cache}