Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created September 27, 2011 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSkorm/1244722 to your computer and use it in GitHub Desktop.
Save TheSkorm/1244722 to your computer and use it in GitHub Desktop.
Simple(ish) hacked up bandwidth logger
#!/bin/bash
#Makes a CSV of UNIX Time, wget speed, and link speed from an SNMP router
TEMPFILE="/tmp/10m"
STARTBYTES=`snmpwalk -OvQ -v2c -c SNMPRO ROUTERIP 1.3.6.1.2.1.2.2.1.10.7`
STARTTIME=`date +%s`
WGETOUTPUT=`/usr/bin/wget -O$TEMPFILE "http://mirror.internode.on.net/pub/test/10meg.test" 2>&1`
FINISHBYTES=`snmpwalk -OvQ -v2c -c SNMPRO ROUTERIP 1.3.6.1.2.1.2.2.1.10.7`
FINISHTIME=`date +%s`
BPS=`echo \(\($FINISHBYTES-$STARTBYTES\)/\($FINISHTIME-$STARTTIME\)\)/1024|/usr/bin/bc`
DATALINE=`echo $WGETOUTPUT | /usr/bin/perl -ne 'print "$1 $2" if /.*(?:\()([0-9]+) (KB|MB)\/s(?:\)).*/' `
echo $STARTTIME,$DATALINE,$BPS KB >> bandwidth.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment