From 5b0aad0638c8702ba386fc1c25ff838868454e3d Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Tue, 12 Jul 2016 15:35:16 +1000 Subject: [PATCH 1/2] [plugins/upnpc_] Add upnpc-based router monitoring plugin Signed-off-by: Olivier Mehani --- plugins/upnpc/upnpc_ | 149 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100755 plugins/upnpc/upnpc_ diff --git a/plugins/upnpc/upnpc_ b/plugins/upnpc/upnpc_ new file mode 100755 index 00000000..d45a7ebf --- /dev/null +++ b/plugins/upnpc/upnpc_ @@ -0,0 +1,149 @@ +#!/bin/sh +# -*- sh -*- + +: << =cut + +=head1 NAME + +upnpc_ - Plugin to monitor routers via UPnP + +=head1 APPLICABLE SYSTEMS + +Linux systems with upnpc installed. + +=head1 CONFIGURATION + +None needed. + +=head1 AUTHOR + +Olivier Mehani + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=cut + +autoconf() { + which upnpc >/dev/null && upnpc -s >/dev/null 2>&1 && echo yes || echo "no (No upnpc or no UPnP router)" +} + +suggest () { + upnpc -s | sed -n " \ + s/.*uptime=.*/uptime/p; \ + s/.*MaxBitRate.*/bitrate/p; \ + s/.*Bytes.*/traffic/p; \ + s/.*Packets.*/pkts/p; \ + " +} + +config () { + case $1 in + "uptime") + cat << EOF +graph_title Uplink connection uptime +graph_args -l 0 +graph_category network +graph_scale no +graph_vlabel uptime in hours +uptime.label uptime +uptime.draw AREA +uptime.cdef uptime,3600,/ +EOF + ;; + "bitrate") + cat << EOF +graph_title Uplink bitrate +graph_args --base 1000 -l 0 +graph_category network +graph_vlabel bitrate down (-) / up (+) +down.label bps +down.warning 4194304: +down.critical 1048576: +up.label bps +up.warning 524288: +up.critical 131072: +down.graph no +up.negative down +EOF + ;; + "traffic") + cat << EOF +graph_title Uplink traffic +graph_args --base 1024 -l 0 +graph_category network +graph_vlabel bytes in (-) / out (+) per ${graph_period} +down.label Bps +down.type DERIVE +down.min 0 +up.label Bps +up.type DERIVE +up.min 0 +down.graph no +up.negative down +EOF + ;; + "pkts") + cat << EOF +graph_title Uplink packets +graph_args --base 1000 -l 0 +graph_category network +graph_vlabel packets in (-) / out (+) per ${graph_period} +down.label pps +down.type DERIVE +down.min 0 +up.label pps +up.type DERIVE +up.min 0 +down.graph no +up.negative down +EOF + ;; + "*") + echo "$0: unknown mode '$1'" >&2 + exit 1 + esac +} + +fetch () { + case $1 in + "uptime") + upnpc -s | sed -n "s/.*uptime=\([0-9]\+\)s.*/uptime.value \1/p" + ;; + "bitrate") + upnpc -s | sed -n "s/^MaxBitRateDown : \([0-9]\+\) bps.*MaxBitRateUp \([0-9]\+\) bps.*/down.value \1\nup.value \2/p" + ;; + "traffic") + upnpc -s | sed -n "s/^Bytes:\s*Sent:\s*\([0-9]\+\).*Recv:\s*\([0-9]\+\).*/up.value \1\ndown.value \2/p" + ;; + "pkts") + upnpc -s | sed -n "s/^Packets:\s*Sent:\s*\([0-9]\+\).*Recv:\s*\([0-9]\+\).*/up.value \1\ndown.value \2/p" + ;; + "*") + echo "$0: unknown mode '$1'" >&2 + exit 1 + esac +} + +mode=`echo $0 | sed 's/.*_//'` + +case $1 in + "autoconf") + autoconf + ;; + "suggest") + suggest + ;; + "config") + config $mode + ;; + *) + fetch $mode + ;; +esac From 20de5307cb43aa65629788e9348a3867257ad727 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Tue, 25 Oct 2016 23:01:58 +1100 Subject: [PATCH 2/2] [upnpc_] Move to network/ and document graphs Signed-off-by: Olivier Mehani --- plugins/{upnpc => network}/upnpc_ | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) rename plugins/{upnpc => network}/upnpc_ (85%) diff --git a/plugins/upnpc/upnpc_ b/plugins/network/upnpc_ similarity index 85% rename from plugins/upnpc/upnpc_ rename to plugins/network/upnpc_ index d45a7ebf..e3c933c5 100755 --- a/plugins/upnpc/upnpc_ +++ b/plugins/network/upnpc_ @@ -7,6 +7,13 @@ upnpc_ - Plugin to monitor routers via UPnP +This plugin uses the upnpc utility (package miniupnpc in Debian), to monitor an +router using UPnP. It can monitor the following aspects, and plot them as separate graphs: +* uptime: how long the link has been up; +* bitrate: the up and downlink bitrate (e.g., sync speed for DSL); +* traffic: the actual up and downstream traffic rate; +* pkts: the number of packets coming in and out. + =head1 APPLICABLE SYSTEMS Linux systems with upnpc installed. @@ -17,7 +24,7 @@ None needed. =head1 AUTHOR -Olivier Mehani +Olivier Mehani =head1 LICENSE