Simple Munin Wifi Traffic Monitor

Another in the endless series of Munin monitors, for the sharing on the internets – Intellinet 450N Wifi Router

The Intellinet 450N Wifi Router I'm using for 802.11N/N5 wifi access has the usual web interface with the usual router statistics. It looks like this:

 

router

Awesome… those packets represent 12000 bits (8*1500 bytes) of data each, and they climb forever. In my application this is used as a dumb access point, so we can ignore the WAN numbers.

 

Right clicking on the Statistics link on the left that leads to this page and copying the link tells me the actual URL for this page is dlink.schettino.us/stats.asp (this is an internal URL, it's not resolvable outside of my network) Yes, I used to have a dlink router here, but it died.

The next bit of info we need is to check how the router does its security – the router asks for a user/pass to access its website, and sure enough it uses simple HTTP authentication.

Armed with that, we have a simple wget call to get this same page:

$ wget -qO- --user=admin --password="your-password-here" http://dlink.schettino.us/stats.asp
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<link rel="stylesheet" href="/file/set.css">
<script type="text/javascript" src="/file/javascript.js"></script>
<script type="text/javascript" src="/file/multilanguage.var"></script>
<script type="text/javascript" src="/FUNCTION_SCRIPT"></script>
<title></title>
</head>
<body class="mainbg">

There's more than that… what we actually need is just the table of packet counts, which are helpfully annotated with a div tag of table2, so:

$ wget -qO- --user=admin --password="your-password-here" http://dlink.schettino.us/stats.asp | grep table2
document.write('<td width="20%" class="table2">&nbsp;86647377</td>');
document.write('<td width="20%" class="table2">&nbsp;61777978</td>');
document.write('<td width="20%" class="table2">&nbsp;105507119</td>');
document.write('<td width="20%" class="table2">&nbsp;133582464</td>');
<td width="20%" class="table2">&nbsp;190666284</td>
<td width="20%" class="table2">&nbsp;191639424</td>
document.write('<td width="20%" class="table2">&nbsp;2628501</td>');
document.write('<td width="20%" class="table2">&nbsp;0</td>');

And here you have the numbers, in the same order as displayed on the web page. So, a little slice and dice with sed will turn these into the values needed for munin. Add in all the munin plugin goodness and you get this plugin:

#!/bin/sh

case $1 in
   config)
        cat <<'EOM'
graph_title wifi router traffic
graph_vlabel bits sent/-recv
graph_category network
graph_info This graph shows Intellinet Wireless 540N traffic
graph_order w24recv w5recv ethrecv w24sent w5sent ethsent
w24sent.type COUNTER
ethsent.type COUNTER
w5sent.type COUNTER
w24recv.type COUNTER
w5recv.type COUNTER
ethrecv.type COUNTER
w24sent.cdef w24sent,12000,*
ethsent.cdef ethsent,12000,*
w5sent.cdef w5sent,12000,*
w24recv.cdef w24recv,12000,*
w5recv.cdef w5recv,12000,*
ethrecv.cdef ethrecv,12000,*
w24recv.graph no
w5recv.graph no
ethrecv.graph no
w24sent.negative w24recv
ethsent.negative ethrecv
w5sent.negative w5recv
w24sent.label Wifi N
w5sent.label Wifi N5
ethsent.label Wired
EOM
        exit 0;;
esac

wget -qO- --user=admin --password="your-password-here" http://dlink.schettino.us/stats.asp | grep table2  | sed -n 
-e '1s/^.*&nbsp;/w24sent.value /' -e "s/</td>//" -e "s/');//" -e '2s/^.*&nbsp;/w24recv.value /' 
-e '3s/^.*&nbsp;/w5sent.value /' -e '4s/^.*&nbsp;/w5recv.value/'  -e '5s/^.*&nbsp;/ethsent.value /' 
-e '6s/^.*&nbsp;/ethrecv.value /' -e "1,6p"

And the result is this wonderful graph:

Fun graphs for everyone!