From 208874d74d128f856ff9ed1c1a24090d480c2898 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Sun, 3 Feb 2013 21:34:36 +0100 Subject: [PATCH 1/4] if1sec_: initial version --- plugins/network/if1sec_ | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 plugins/network/if1sec_ diff --git a/plugins/network/if1sec_ b/plugins/network/if1sec_ new file mode 100755 index 00000000..fe07f4a9 --- /dev/null +++ b/plugins/network/if1sec_ @@ -0,0 +1,44 @@ +#! /bin/sh + +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 + +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; + }" >> $cache & + echo $! > $pidfile + exit 0 +fi + + +if [ "$1" = "config" ] +then + cat < ${FILE_VALUES} + +exit 0 + From 63d61bc52e0c6952277537453143940543a397df Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Mon, 4 Feb 2013 10:18:40 +0100 Subject: [PATCH 2/4] if1sec: fixes --- plugins/network/if1sec_ | 45 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/plugins/network/if1sec_ b/plugins/network/if1sec_ index fe07f4a9..a08cd906 100755 --- a/plugins/network/if1sec_ +++ b/plugins/network/if1sec_ @@ -7,38 +7,49 @@ cache="$MUNIN_PLUGSTATE/munin.$plugin.value" IFACE="${0##*/if1sec_}" # interface +if [ ! -r "/sys/class/net/$IFACE/statistics/tx_bytes" ] +then + echo "# Unknown Interface : $IFACE" + exit 1 +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; - }" >> $cache & + ( + 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; + }" >> $cache + ) & echo $! > $pidfile - exit 0 + exit 0 fi if [ "$1" = "config" ] then - cat < ${FILE_VALUES} +cat ${cache} +> ${cache} exit 0 - From 2fd52dfb38e4a55c357784485f5e397d6f1a1eed Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Mon, 4 Feb 2013 10:52:02 +0100 Subject: [PATCH 3/4] if1sec_: adding a proper label --- plugins/network/if1sec_ | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/network/if1sec_ b/plugins/network/if1sec_ index a08cd906..992e7547 100755 --- a/plugins/network/if1sec_ +++ b/plugins/network/if1sec_ @@ -39,9 +39,12 @@ then graph_title Interface 1sec stats for ${IFACE} graph_category 1sec::network graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y +graph_vlabel Bytes update_rate 1 +${IFACE}_tx.label ${IFACE} TX bytes ${IFACE}_tx.type DERIVE ${IFACE}_tx.min 0 +${IFACE}_rx.label ${IFACE} RX bytes ${IFACE}_rx.type DERIVE ${IFACE}_rx.min 0 EOF From 7beab0e4203f2247f08c62038cc6edfa8877f1bf Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Mon, 4 Feb 2013 10:52:29 +0100 Subject: [PATCH 4/4] if1sec_: explicit flushing when appending to cache --- plugins/network/if1sec_ | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/network/if1sec_ b/plugins/network/if1sec_ index 992e7547..6e5ad6d4 100755 --- a/plugins/network/if1sec_ +++ b/plugins/network/if1sec_ @@ -26,6 +26,7 @@ then done | awk "{ print \"${IFACE}_tx.value \" \$1 \":\" \$2; print \"${IFACE}_rx.value \" \$1 \":\" \$3; + system(\"\"); }" >> $cache ) & echo $! > $pidfile