Get Usage Stats from Netgear DG834G Router
Last Updated on Wednesday, 2 December 2009 12:00 Written by admin Thursday, 3 September 2009 01:43
Initially I tried off-the-shelf applications like PRTG and Router Stats but they did not fit the bill for various reasons, not least the poor SNMP support on the DG843G router.
Then I stumbled upon a telnet reference that extracted the upload and download stats from my router.
After hacking some vbscript about a bit I produced the code below. Now, before you flame me for my poor code let me just say that I am not a professional programmer and only attempt this sort of thing once in a blue moon.
The purpose of the code is to log the router’s stats to a text file on a regular basis. This file can then be imported into Excel (or another application of your choice) for graphing etc.
The code produces a three column text file that looks like this:-
06/09/2009 08:00:00Â Â Â 2566906384Â Â Â 420938933
06/09/2009 08:15:00Â Â Â 2567674326Â Â Â 421835475
06/09/2009 08:30:00Â Â Â 2571321533Â Â Â 425060305
06/09/2009 08:45:00Â Â Â 2571606416Â Â Â 426546073
06/09/2009 09:00:00Â Â Â 2571722487Â Â Â 430474825
06/09/2009 09:15:00Â Â Â 2571827612Â Â Â 430826412
06/09/2009 09:30:00Â Â Â 2571883066Â Â Â 431213154
06/09/2009 09:45:00Â Â Â 2571932634Â Â Â 431365976
06/09/2009 10:00:00Â Â Â 2572103375Â Â Â 432212404
06/09/2009 10:15:00Â Â Â 2572240782Â Â Â 432670760
The Date/timestamp is a single column, the uploaded, and the downloaded byte counts are tab separated.
Setting the Task Scheduler to run this script every 15 minutes does the job for me.
RouterUsageStats.vbs
‘ ”””””””””””””””””””””””””””””””””’
‘ The following code extracts both upload and download byte counts
‘ from a Netgear DG834G router and writes them into a log file.
‘ Schedule this utility to run from Task manager every 15mins
‘ (for example).
‘ NOTE: this utility relies on a DLL file, “socket.dll” – which can
‘ be downloaded free from http://tech.dimac.net/ – It is called
‘ “w3sockets”.
‘ Output is appended to the bottom of C:\utils\usage.log
‘ Each line looks like: “02/09/2009 22:15:00 455400415 501201425″
‘ The two numbers being cumulative totals for uploads and downloads
‘ respectively.
‘ 2/9/09
‘ ”””””””””””””””””””””””””””””””””’
Dim w3sock, contents, TxTotalBytesStart, TxTotalBytesEnd, RxTotalBytesStart, RxTotalBytesEnd
Dim TxTotalBytes, RxTotalBytes, DataLine
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set w3sock = CreateObject(“Socket.TCP”)
Set fso = CreateObject(“Scripting.FileSystemObject”)
w3sock.DoTelnetEmulation = True
w3sock.TelnetEmulation = “TTY”
w3sock.Host = “192.168.2.1:23″
w3sock.Open
w3sock.SendLine “cat /proc/avalanche/avsar_modem_stats | grep ‘ Total Bytes:’”
‘ the above line extracts the following from the router
‘ ”””””””””””””””””””””””””””””””””’
‘ cat /proc/avalanche/avsar_modem_stats | grep ‘ Total ‘
‘
‘
‘
‘ BusyBox v0.61.pre (2008.06.11-10:37+0000) Built-in shell (ash)
‘ Enter ‘help’ for a list of built-in commands.
‘
‘ # cat /proc/avalanche/avsar_modem_stats | grep ‘ Total ‘
‘ Tx Total Bytes: 396768076
‘ Rx Total Bytes: 332285881
‘ #
‘ #
‘ ”””””””””””””””””””””””””””””””””’
w3sock.WaitFor “Rx Total Bytes:”
‘Wscript.echo w3Sock.Buffer
w3sock.Close
Set outfile = fso.OpenTextFile(“c:\Utils\usage.log”,ForAppending,true)
contents = w3Sock.Buffer
‘ ”””””””””””””””””””””””””””””””””’
‘ Parse ‘contents’ for TX and RX numbers
‘ ”””””””””””””””””””””””””””””””””’
TxTotalBytesStart = 16 +(InStr(contents, “Tx Total Bytes: “))
TxTotalBytesEnd = InStr(TxTotalBytesStart, contents, Chr(13))
TxTotalBytes = Mid(contents, TxTotalBytesStart, (TxTotalBytesEnd – TxTotalBytesStart))
RxTotalBytesStart = 16 +(InStr(contents, “Rx Total Bytes: “))
RxTotalBytesEnd = InStr(RxTotalBytesStart, contents, Chr(13))
RxTotalBytes = Mid(contents, RxTotalBytesStart, (RxTotalBytesEnd – RxTotalBytesStart))
‘ ”””””””””””””””””””””””””””””””””’
‘ Assemble & output data to log file
‘ ”””””””””””””””””””””””””””””””””’
DataLine = Date &” “& Time &chr(9)& TxTotalBytes &chr(9)& RxTotalBytes
outfile.WriteLine DataLine
outfile.Close
