#!/bin/bash # License: GPLv2 # Adapted from: http://munin-monitoring.org/browser/munin-contrib/plugins/network/traffic # Authors: Arturo Borrero Gonzalez, Michiel Holtkamp, Merten Peetz statefiledir=$MUNIN_PLUGSTATE muninhost=$MUNIN_MASTER_IP type=`cut -d "_" -f 2 <<< "$0"` if [ "$1" == "config" ] then if [ "$type" = "total" ] then cat <<'EOF' graph_title Throughput by IP protocol graph_vlabel bits per ${graph_period} graph_category network graph_args --base 1000 --upper-limit 100 -l 0 IPv4.label IPv4 bps IPv4.min 0 IPv4.type DERIVE IPv4.draw AREA IPv6.label IPv6 bps IPv6.min 0 IPv6.type DERIVE IPv6.draw STACK total.label Total bps total.min 0 total.type DERIVE total.draw LINE1 EOF else cat <<'EOF' graph_scale no graph_title Throughput of IP protocols by percentage graph_vlabel Percentage graph_category network graph_args --upper-limit 100 -l 0 -r IPv4.label IPv4 % IPv4.min 0 IPv4.draw AREA IPv6.label IPv6 % IPv6.min 0 IPv6.draw STACK EOF fi else total=0 if [ -r /proc/net/dev ] then for i in $(fgrep -v -e bond -e lo /proc/net/dev | awk -F' ' '{print $2+$10}') do total=$(( total + i * 8 )) done else echo "W: Unable to read /proc/net/dev" >&2 fi ipv6=0 if [ -r /proc/net/dev_snmp6 ] then for i in $(ls /proc/net/dev_snmp6 | grep -v -e bond -e lo) do for j in $(fgrep -e Ip6InOctets -e Ip6OutOctets /proc/net/dev_snmp6/$i | awk -F' ' '{print $2}') do ipv6=$(( ipv6 + j * 8 )) done done else echo "W: Unable to read /proc/net/dev_snmp6/" >&2 fi ipv4=$(( total - ipv6 )) if [ "$type" = "total" ] then echo "IPv4.value $ipv4" echo "IPv6.value $ipv6" echo "total.value $total" else ipv4_f="${statefiledir}/ipv6_traffic_ipv4-${muninhost}" ipv6_f="${statefiledir}/ipv6_traffic_ipv6-${muninhost}" if [[ -a $ipv4_f && -a $ipv6_f ]] then ipv4_c=$(<$ipv4_f) ipv6_c=$(<$ipv6_f) ipv4_c=$(( ipv4 - ipv4_c )) ipv6_c=$(( ipv6 - ipv6_c )) total_c=$(( ipv4_c + ipv6_c )) if [ "$total_c" != 0 ] then # Insert decimal point at 2 offset from the right to avoid requiring bc # We could use Munin .cdef instead but that would screw up old data ipv4_p=`echo $(( 10000 * ipv4_c / total_c )) | sed 's/..$/.&/;t;s/^.$/.0&/'` ipv6_p=`echo $(( 10000 * ipv6_c / total_c )) | sed 's/..$/.&/;t;s/^.$/.0&/'` echo "IPv4.value $ipv4_p" echo "IPv6.value $ipv6_p" fi fi echo $ipv4 > $ipv4_f echo $ipv6 > $ipv6_f fi fi