From 1aac06d3e9ed922dfd9187c88a6322185c1a03d5 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Wed, 14 Nov 2018 13:05:29 +0330 Subject: [PATCH] Add modified if_ and if_packets_ munin plugin that uses ifcounters instead of netstat --- if_ | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ if_packets_ | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100755 if_ create mode 100755 if_packets_ diff --git a/if_ b/if_ new file mode 100755 index 0000000..f3a1856 --- /dev/null +++ b/if_ @@ -0,0 +1,62 @@ +#!/bin/sh +# -*- sh -*- +# +# Wildcard-plugin to monitor network interfaces. To monitor an +# interface, link if_ to this file. E.g. +# +# ln -s /usr/local/share/munin/plugins/if_ /usr/local/etc/munin/plugins/if_em0 +# +# ...will monitor em0 interface. +# +# Magic markers (optional - used by munin-config and some installation +# scripts): +# +#%# family=auto +#%# capabilities=autoconf suggest + +INTERFACE=${0##*if_} +IFCOUNTERS="/usr/local/bin/ifcounters" + +if [ "$1" = "autoconf" ]; then + if [ -x /sbin/ifconfig -o -x ${IFCOUNTERS} ]; then + echo yes + exit 0 + else + echo "no (${IFCOUNTERS} not found)" + exit 0 + fi +fi + +if [ "$1" = "suggest" ]; then + if [ -x /sbin/ifconfig ] + then + ifconfig -l | sed -Ee 's/[[:<:]](pfsync|faith|pf(log|sync)|lo|plip|carp|enc|fwe)[^ ]*//g' | xargs -n 1 echo + exit 0 + else + exit 1 + fi +fi + +if [ "$1" = "config" ]; then + echo "graph_order rbytes obytes" + echo "graph_title $INTERFACE traffic" + echo 'graph_args --base 1000' + echo 'graph_vlabel bits per ${graph_period} in (-) / out (+)' + echo 'graph_category network' + echo "graph_info This graph shows the traffic of the $INTERFACE network interface. Please note that the traffic is shown in bits per second, not bytes. IMPORTANT: Since the data source for this plugin use 32bit counters, this plugin is really unreliable and unsuitable for most 100Mb (or faster) interfaces, where bursts are expected to exceed 50Mbps. This means that this plugin is unsuitable for most production environments." + echo 'rbytes.label received' + echo 'rbytes.type DERIVE' + echo 'rbytes.graph no' + echo 'rbytes.cdef rbytes,8,*' + echo 'rbytes.min 0' + echo 'obytes.label bps' + echo 'obytes.type DERIVE' + echo 'obytes.negative rbytes' + echo 'obytes.cdef obytes,8,*' + echo 'obytes.min 0' + echo 'obytes.draw AREA' + echo "obytes.info Traffic sent (+) and received (-) on the $INTERFACE network interface." + exit 0 +fi + +${IFCOUNTERS} -b ${INTERFACE} diff --git a/if_packets_ b/if_packets_ new file mode 100755 index 0000000..b8aeba0 --- /dev/null +++ b/if_packets_ @@ -0,0 +1,65 @@ +#!/bin/sh +# -*- sh -*- +# +# Wildcard-plugin to monitor network interfaces. To monitor an +# interface, link if_packets_ to this file. E.g. +# +# ln -s /usr/local/share/munin/plugins/if_packets_ /usr/local/etc/munin/plugins/if_packets_em0 +# +# ...will monitor eth0 interface. +# +# Magic markers (optional - used by munin-config and some installation +# scripts): +# +#%# family=auto +#%# capabilities=autoconf suggest + +INTERFACE=${0##*if_packets_} +IFCOUNTERS="/usr/local/bin/ifcounters" + +if [ "$1" = "autoconf" ]; then + if [ -x /sbin/ifconfig -o -x ${IFCOUNTERS} ]; then + echo yes + exit 0 + else + echo "no (${IFCOUNTERS} not found)" + exit 0 + fi +fi + +if [ "$1" = "suggest" ]; then + if [ -x /sbin/ifconfig ] + then + ifconfig -l | sed -Ee 's/[[:<:]](pfsync|faith|pf(log|sync)|lo|plip|carp|enc|fwe)[^ ]*//g' | xargs -n 1 echo + exit 0 + else + exit 1 + fi +fi + +if [ "$1" = "config" ]; then + + echo "graph_order rpackets opackets" + echo "graph_title $INTERFACE pps" + echo 'graph_args --base 1000' + echo 'graph_vlabel packets per ${graph_period} in (-) / out (+)' + echo 'graph_category network' + echo "graph_info This graph shows the packets counter of the $INTERFACE network interface. Please note that the traffic is shown in packets per second." + echo 'rpackets.label received' + echo 'rpackets.type COUNTER' + echo 'rpackets.graph no' + + echo 'rpackets.min 0' + echo 'opackets.label pps' + echo 'opackets.type COUNTER' + echo 'opackets.colour COLOUR19' + echo 'opackets.draw AREA' + echo 'opackets.negative rpackets' + + echo 'opackets.min 0' + echo "opackets.info Packets sent (+) and received (-) on the $INTERFACE network interface." + exit 0 +fi + +${IFCOUNTERS} -p ${INTERFACE} +