Speed Test RRD Setup

#First we need to install speedtest-cli.

#For Ubuntu and Raspberry Pi:

sudo apt-get install python-pip
pip install speedtest-cli
sudo pip install speedtest-cli

#For CentOS and the Like:

http://www.cyberciti.biz/faq/install-speedtest-cli-on-centos-redhat-fedoa-scientific-to-measure-internetspeed/

#Make Sure you have rrdtool installed:

sudo yum install rrdtool

##Create Graphs

mkdir /etc/speedtest
cd /etc/speedtest

##Then RRDTOOL magic:

sudo rrdtool create speedtest_dl.rrd -s 1800 DS:temp:GAUGE:3600:0:125 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

sudo rrdtool create speedtest_ms.rrd -s 1800 DS:temp:GAUGE:3600:0:1000 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

sudo rrdtool create speedtest_up.rrd -s 1800 DS:temp:GAUGE:3600:0:125 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

##Then Create a script to run speedtest-cli, clean it up and stuff it into RRD

vi /usr/local/bin/speedtest-rrd

#! /bin/sh

#get into /tmp
cd /tmp

# get the EPOCH date
DATE=$(/bin/date +%s)

#Get the raw data
/usr/local/bin/speedtest-cli --simple > /tmp/speedtest-rrd.txt

#Clean it up and get raw Ping time in ms
RAW_MS=$(cat /tmp/speedtest-rrd.txt | grep P | sed -r 's/\s+//g'| cut -d":" -f2 | cut -d"m" -f1)

#Clean it up and get raw Download time in MiB
RAW_DL=$(cat /tmp/speedtest-rrd.txt | grep D | sed -r 's/\s+//g'| cut -d":" -f2 | cut -d"M" -f1)

#Clean it up and get raw Upload time in MiB
RAW_UP=$(cat /tmp/speedtest-rrd.txt | grep U | sed -r 's/\s+//g'| cut -d":" -f2 | cut -d"M" -f1)

#get data into rrd
cd /etc/speedtest/
rrdtool update speedtest_ms.rrd $DATE:$RAW_MS
rrdtool update speedtest_dl.rrd $DATE:$RAW_DL
rrdtool update speedtest_up.rrd $DATE:$RAW_UP

#create the daily graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_day.png -s -1day DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_day.png -s -1day DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_day.png -s -1day DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create the weekly graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_week.png -s -1week DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_week.png -s -1week DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_week.png -s -1week DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create the monthly graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_month.png -s -1month DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_month.png -s -1month DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_month.png -s -1month DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create the yearly graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_year.png -s -1year DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_year.png -s -1year DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_year.png -s -1year DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Clean up
rm /tmp/speedtest-rrd.txt

 

##Add to Cron

sudo crontab -e

#Add this to the bottom to run every 30 Minutes

*/30 * * * * /usr/local/bin/speedtest-rrd > /dev/null 2>&1

#

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather