From fec8686c4edca8b78b273354626d4c88bb777746 Mon Sep 17 00:00:00 2001 From: Sven Hartge Date: Fri, 20 Apr 2012 00:49:14 +0200 Subject: [PATCH 1/2] arp: simple plugins to monitor a hosts ARP cache --- plugins/arp/arp | 43 +++++++++++++++++++++++++++++++++++++ plugins/arp/arp_ | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100755 plugins/arp/arp create mode 100755 plugins/arp/arp_ diff --git a/plugins/arp/arp b/plugins/arp/arp new file mode 100755 index 00000000..a6657551 --- /dev/null +++ b/plugins/arp/arp @@ -0,0 +1,43 @@ +#!/bin/sh +# +# Plugin to monitor total ARP entries +# +# Parameters understood: +# +# config (required) +# autoconf (optional) +# +# Made by Sven Hartge (sven AT svenhartge DOT de) +# + +#%# family=contrib +#%# capabilities=autoconf + +if [ "$1" = "autoconf" ]; then + # Search for arp + which arp >/dev/null 2>/dev/null || (echo "no (can't find arp binary)" && exit 1) + + # ...or success + echo yes + exit 0 +fi + + + +if [ "$1" = "config" ]; then + echo 'graph_title ARP entries' + echo 'graph_args --base 1000 -l 0' + echo 'graph_vlabel Entries' + echo 'graph_category network' + echo 'graph_scale no' + echo 'graph_info This graph shows the number of ARP entries registered by the system.' + echo 'entries.label ARP entries' + echo 'entries.draw LINE2' + echo 'entries.type GAUGE' + echo 'entries.info Number of ARP entries' + exit 0 +fi + +echo -n "entries.value " +arp -an | grep -v "incomplete" | awk '{ print $4; }' | sort -u | wc -l + diff --git a/plugins/arp/arp_ b/plugins/arp/arp_ new file mode 100755 index 00000000..24667f02 --- /dev/null +++ b/plugins/arp/arp_ @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Plugin to monitor ARP entries per interface +# +# Parameters understood: +# +# config (required) +# autoconf (optional) +# +# Made by Sven Hartge (sven AT svenhartge DOT de) +# +# + + +#%# family=contrib +#%# capabilities=autoconf suggest + +INTERFACE=`basename $0 | sed 's/^arp_//g' | tr '_' '.'` + +if [ "$1" = "autoconf" ]; then + # Search for arp + which arp >/dev/null 2>/dev/null || (echo "no (can't find arp binary)" && exit 1) + + # ...or success + echo yes + exit 0 +fi + +if [ "$1" = "suggest" ]; then + if [ -r /proc/net/dev ]; then + egrep '^ *(eth|wlan|ath|ra)[0-9]+(\.[0-9]+)?:' /proc/net/dev | cut -f1 -d: | sed 's/ //g' | tr '.' '_' + exit 0 + else + exit 1 + fi +fi + + + +if [ "$1" = "config" ]; then + echo "graph_title ARP entries for $INTERFACE" + echo 'graph_args --base 1000 -l 0' + echo 'graph_vlabel Entries' + echo 'graph_category network' + echo 'graph_scale no' + echo "graph_info This graph shows the number of ARP entries registered by the system for interface $INTERFACE." + echo 'entries.label ARP entries' + echo 'entries.draw LINE2' + echo 'entries.type GAUGE' + echo 'entries.info Number of ARP entries' + exit 0 +fi + +echo -n "entries.value " +arp -an -i $INTERFACE | grep -v "incomplete" | awk '{ print $4; }' | sort -u | wc -l + From 4a56eb18976700f6fc460a1b910544421a484cf2 Mon Sep 17 00:00:00 2001 From: Sven Hartge Date: Fri, 20 Apr 2012 15:19:22 +0200 Subject: [PATCH 2/2] arp: use only awk to process ARP cache Simplify the processing of the output of arp -an to use only awk. Reduces the needed subprocesses in the pipe. --- plugins/arp/arp | 3 +-- plugins/arp/arp_ | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/arp/arp b/plugins/arp/arp index a6657551..8addffa3 100755 --- a/plugins/arp/arp +++ b/plugins/arp/arp @@ -38,6 +38,5 @@ if [ "$1" = "config" ]; then exit 0 fi -echo -n "entries.value " -arp -an | grep -v "incomplete" | awk '{ print $4; }' | sort -u | wc -l +arp -an | awk 'BEGIN { regex="";} { if (!match($4,regex)) { a[$4] }} END{for(i in a){n++};print "entries.value " n}' diff --git a/plugins/arp/arp_ b/plugins/arp/arp_ index 24667f02..adbd86c3 100755 --- a/plugins/arp/arp_ +++ b/plugins/arp/arp_ @@ -51,6 +51,5 @@ if [ "$1" = "config" ]; then exit 0 fi -echo -n "entries.value " -arp -an -i $INTERFACE | grep -v "incomplete" | awk '{ print $4; }' | sort -u | wc -l +arp -an -i $INTERFACE | awk 'BEGIN { regex="";} { if (!match($4,regex)) { a[$4] }} END{for(i in a){n++};print "entries.value " n}'