... ...

Anagram Solver Solar Artwork

TuftedPuffin.co.uk

... ...

 

... ...
 

Live Data

Live

Today

Yesterday

Energy

PV

Electricity Usage

Write Up

Introduction

OneWire

Scripts

Mysql

Gnuplot

Energy

Theoretical

SVG

Behaviour

PV Monitor

Current Monitor

Bandwidth Monitor

Getting Network Statistics from a Netgear DG384

My ADSL modem is a Netgear DG384, it's a relatively old thing, but still does the job it's meant to do pretty well.

My ISP limits my bandwidth if I use too much, so I wanted to be able to monitor my usage.

The DG384 does have a web interface that shows number of packets sent and received, but that's a total number. I want to know what my usage is over a certain period

There's a back door available on the DG384. A debug option can be turned on via the web interface. In the address bar of your browser type :-

10.0.1.2/setup.cgi?todo=debug

Where 10.0.1.2 is the network address of my DG384

This puts the DG384 into debug mode. Which has no effect on the performance of the unit, but it does enable a telnet interface. The unit can be logged into using :-

telnet 10.0.1.2

No user name or password is required

The DG384 is a Linux based unit, and has the normal Linux file system structure. Most of the statistics available on the DG384 web interface are held in files in the /tmp directory

Other more basic information is available in the /proc directory

Because I was interested in net usage I target the file /proc/net/dev. This file contains a count of the number of bytes and packets that have been sent and received on each of the DG384's interfaces

A perl script ( netmon.prl ) allows me to access this file programatically

use Net::Telnet;

$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Prompt=> '/#/' );

$telnet->open( '10.0.1.2' );

$telnet->waitfor('/#/' );

$telnet->print('cat /proc/net/dev' );

($output) = $telnet->waitfor('/#/');

print $output;

The perl extension libnet-telnet-perl needs to be installed for this to work

Now typing perl netmon.prl dumps the network statistics to the console

To get this information into a database I added some tables to my "house" database, one table for each interface.

drop table IF EXISTS lo;

drop table IF EXISTS atm0;

drop table IF EXISTS cpcs0;

drop table IF EXISTS dsl0;

drop table IF EXISTS eth0;

drop table IF EXISTS br0;

drop table IF EXISTS wifi0;

drop table IF EXISTS ath0;

drop table IF EXISTS ppp0;

create table lo ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table atm0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table cpcs0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table dsl0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table eth0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table br0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table wifi0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table ath0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

create table ppp0 ( day datetime primary key, BytesRx bigint, BytesTx bigint, PacketsRx bigint, PacketsTx bigint );

A simple script is then called from cron on a regular basis to get the stats and put them into the database

#!/bin/bash

cd /home/steve/netmonitor

perl netmon.prl | sed -e "s/:/ /" | awk '{if ( NR > 3 ) { print "INSERT INTO " $1," VALUES( \"" strftime( "%F %R") "\",", $2,",", $10,",", $3,",", $11, ");"} }' | mysql -usteve house

The script gets the data from the DG384, pipes it through sed to convert the colon to a space, pipes that through awk to extract the fields I'm interested in and then pipes that to mysql to put the data into a database. Note that the name of the interface, i.e. $1 is used as the name of the table.

Gnuplot scripts to plot net usage will be written at a later date

This page is best viewed using Firefox Spread Firefox Affiliate Button

 

... ...