Nice: you can use UPnP to read the amount of bytes Received and Sent by your NAT router. And with a little AWK scripting, you can feed that to MRTG to have your traffic in a graph.
Here's how:
On Linux you can use the command "upnpc -s" for that. On Ubuntu, upnpc is provided by the package miniupnpc. Once upnpc is installed, run "upnpc -s" to see that it works. If it doesn't, make sure UPnP is enabled on your router.
Then create a script upnpc2mrtg.sh with these contents:
upnpc -s | awk '
BEGIN { }
/uptime=/{ uptime = int(substr($4,8,100) / 3600) }
/Found valid IGD/{ split($5, a, "/") ; split(a[3], b, ":") ; igdip = b[1] }
/Bytes:/{ print $5 "\n" $3 }
END{ print uptime " hours \nIGD at " igdip "\n" }
'
Make the script executable, and run it. The output should be like:
$ ./upnpc2mrtg.sh
3571486807
2422632348
116 hours
IGD at 192.168.0.1
Then add this to your mrtg config file:
Title[upnprouter]: Router via UPnP
Target[upnprouter]: `/path/to/script/upnpc2mrtg.sh`
Options[upnprouter]: growright,bits
MaxBytes[upnprouter]: 10000000000
WithPeak[upnprouter]: ymw
That should give a nice graph.
PS: UPnP itself or upnpc works with 32 bit counters. So if you do more than 4.2 GB per 5 minutes, MRTG will show incorrect results.
Here's how:
On Linux you can use the command "upnpc -s" for that. On Ubuntu, upnpc is provided by the package miniupnpc. Once upnpc is installed, run "upnpc -s" to see that it works. If it doesn't, make sure UPnP is enabled on your router.
Then create a script upnpc2mrtg.sh with these contents:
upnpc -s | awk '
BEGIN { }
/uptime=/{ uptime = int(substr($4,8,100) / 3600) }
/Found valid IGD/{ split($5, a, "/") ; split(a[3], b, ":") ; igdip = b[1] }
/Bytes:/{ print $5 "\n" $3 }
END{ print uptime " hours \nIGD at " igdip "\n" }
'
Make the script executable, and run it. The output should be like:
$ ./upnpc2mrtg.sh
3571486807
2422632348
116 hours
IGD at 192.168.0.1
Then add this to your mrtg config file:
Title[upnprouter]: Router via UPnP
Target[upnprouter]: `/path/to/script/upnpc2mrtg.sh`
Options[upnprouter]: growright,bits
MaxBytes[upnprouter]: 10000000000
WithPeak[upnprouter]: ymw
That should give a nice graph.
PS: UPnP itself or upnpc works with 32 bit counters. So if you do more than 4.2 GB per 5 minutes, MRTG will show incorrect results.