ISR : Internet Speed Report

by Acmecorporation in Circuits > Software

1438 Views, 19 Favorites, 0 Comments

ISR : Internet Speed Report

speedupdown.png
ping.png

Sometimes happen that my internet connection is very slow or offline. Several times i've issued claim to phone company, but their usual answers was that my modem isn't newest or is broken or ......etc.etc.....

So i wrote this simple script that do following functions:

  • obtain ping value
  • obtain download/upload rate
  • plot a graph and send it by email

With detailed speed report in my hands, i've re-send the claim. After this phone company has recognized the problem.

Now i'm going with 14Mbps of download rate and 7ms of ping, i think it's a good results for DSL connection.

This Instructables is based on Debian Wheezy for Raspberry 3.12.35+ #730

but you can adapt to all Linux based OS

What You Need:

IMG_0244a.jpg

Hardware:

- Raspberry Pi

Software:

- Speedtest client

- Gnuplot

- Sendemail (with TLS support for Gmail)

Software Installation

Speedtest client installation:

into your home directory:

$ wget https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
$ chmod a+rx speedtest_cli.py  
$ sudo mv speedtest_cli.py /usr/local/bin/speedtest-cli
$ sudo chown root:root /usr/local/bin/speedtest-cli

test it writing following command:

$ speedtest-cli

GNUPLOT installation:

into your home directory write:

$ sudo apt-get install gnuplot-x11

answer "Y" if prompeted

Sendemail installation:

assuming that you have a gmail account, follow these instructions

$ wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

extract it:

$ tar -zxvf sendEmail-v1.56.tar.gz

copy to correct path:

$ sudo cp -a sendEmail-v1.56/sendEmail /usr/local/bin

make it executable

Install TLS support for Gmail

$ sudo apt-get install libnet-ssleay-perl libio-socket-ssl-perl

after installing, change it as follow:

$ sudo nano /usr/share/perl5/IO/Socket/SSL.pm

with CTRL-W find the line with this argument:

m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1[12]?))$}i

and change it to:

m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1[12]?))}i

save and exit

try to send an email with the command line:

$ sendEmail -f YOUREMAIL@gmail.com -t YOUREMAIL@gmail.com -u "OBJECT" -m "MESSAGE TEXT" -xu YOUREMAIL@gmail.com -xp YOURPASSWORD -o tls=yes -s smtp.gmail.com:587

Speed/ping Script

create folder and subfolder:

$ mkdir isr
$ cd isr
$ mkdir data

copy following script or download the attachment inside isr directory:

$ nano internetspeed.sh

#!/bin/bash


#### This script create n.3 files with ping, dowload and upload speed using ####

#### Speedtest client and ping command ###############################

#### create two files with ping and dowload/upload speed###################

speedtest-cli > /home/pi/isr/speed.txt ;

ping -c 1 google.com > /home/pi/isr/ping.txt ;

#### setting variables

d=`date +%d%m%Y`

ping=$d"ping.txt"

up=$d"upload.txt"

dow=$d"download.txt"

#### check if daily ping, dowload and upload speed database has been created yet. If not

#### create new files

if [ -f /home/pi/isr/data/$ping ]; then

date +%Y-%m-%d" "%H:%M";" | tr -d '\012\015' >> /home/pi/isr/data/$ping

else

touch /home/pi/isr/data/$ping | date +%Y-%m-%d" "%H:%M";" | tr -d '\012\015' >> /home/pi/isr/data/$ping

fi

if [ -f /home/pi/isr/data/$up ]; then

date +%Y-%m-%d" "%H:%M";" | tr -d '\012\015' >> /home/pi/isr/data/$up

else

touch /home/pi/isr/data/$up | date +%Y-%m-%d" "%H:%M";" | tr -d '\012\015' >> /home/pi/isr/data/$up

fi

if [ -f /home/pi/isr/data/$dow ]; then

date +%Y-%m-%d" "%H:%M";" | tr -d '\012\015' >> /home/pi/isr/data/$dow

else

touch /home/pi/isr/data/$dow | date +%Y-%m-%d" "%H:%M";" | tr -d '\012\015' >> /home/pi/isr/data/$dow

fi

#### check if dates already exists. If yes, add ping and speed values to databases.

#### If not, add 0.00 value to databases

atr=`sed -n 2p /home/pi/isr/ping.txt`

att=`expr match "$atr" '.*\([time=]...*\)' | sed -e s/'='/''/g | sed -e s/' ms'/''/g`

if [ "$att" == "" ]; then

echo "0.00" >> /home/pi/isr/data/$ping

else

echo "$att" >> /home/pi/isr/data/$ping

fi

utr=`sed -n 9p /home/pi/isr/speed.txt`

utt=`expr match "$utr" '.*\([:]...*\)' | sed -e s/': '/''/g | sed -e s:' Mbit/s':'':g`

if [ "$utt" == "" ]; then

echo "0.00" >> /home/pi/isr/data/$up

else

echo "$utt" >> /home/pi/isr/data/$up

fi

str=`sed -n 7p /home/pi/isr/speed.txt`

stt=`expr match "$str" '.*\([:]...*\)' | sed -e s/': '/''/g | sed -e s:' Mbit/s':'':g`

if [ "$stt" == "" ]; then

echo "0.00" >> /home/pi/isr/data/$dow

else

echo "$stt" >> /home/pi/isr/data/$dow

fi

save & exit

Downloads

Plot Script

always inside /home/pi/isr directory, copy following script or dowload the attachment:

$ nano plot.sh

#!/bin/sh

d=`date +%d%m%Y`

ping=$d"ping.txt"

up=$d"upload.txt"

dow=$d"download.txt"

FILE=/home/pi/isr/data/$dow

FILEA=/home/pi/isr/data/$up

FILEB=/home/pi/isr/data/$ping

now=$(date +"%d_%m_%Y")

gnuplot -persist <

set datafile separator ";"

set grid

set xdata time

set timefmt '%Y-%m-%d %H:%M'

set xtics format '%H:%M'

set xlabel "Time"

set ylabel "Mbit/s"

set terminal png medium

set output "/home/pi/isr/speedupdown.png"

set title "upload/download speed $now"

plot "$FILE" using 1:(column(2)) t "Upload" with lines lt 1 lw 3 linecolor 2, "$FILEA" using 1:(column(2)) t "Download" with lines lt 1 lw 3 linecolor 1

quit

PLOT

gnuplot -persist <

set datafile separator ";"

set grid

set xdata time

set timefmt '%Y-%m-%d %H:%M'

set xtics format '%H:%M'

set xlabel "Time Ping 0ms = offline"

set ylabel "milliseconds"

set terminal png medium

set output "/home/pi/isr/ping.png"

set title "ping google.com $now"

plot "$FILEB" using 1:(column(2)) t "Latency" with lines lt 1 lw 3 linecolor 3

quit

PLOT

sendEmail -f YOUREMAIL@gmail.com -t YOUREMAIL@gmail.com -u "Internet Speed Reports" -m "Upload/Download/Ping" -xu YOUREMAIL@gmail.com -xp YOURPASSWORD -o tls=yes -s smtp.gmail.com:587 -a /home/pi/isr/speedupdown.png /home/pi/isr/ping.png

add your correct gmail address and password, save and exit.

Downloads

Final Settings

We are going to cron sript internetspeed.sh

To check ping and speed every 20 minutes:

$ sudo nano /etc/crontab

add:

*/20 * * * * pi bash /home/pi/isr/internetspeed.sh

Do not check massively your speed. Allow SpeedClient servers free for other users, pls. Many testings are not goods for your internet speed too. I turn ISR on each time that internet connection seems go too much slow.

You can receive by email your daily internet speed report whenever you want with following command:

$ bash isr/plot.sh

My favourite setting is to receive email report at the end of day, so i cron the script plot.sh as follow:

$ sudo nano /etc/crontab

add:

00 23 * * * pi bash /home/pi/isr/internetspeed.sh

...and

thank you and enjoy!