Automated speedtests using speedtest-cli
Due to issues with my ISP, i wrote a really quick automated speedtest using speedtest-cli which sends the output to graphite.
This is is a quick script i knocked up which runs speedtest-cli, parses the output then fires it over to graphite (just using netcat, nothing fancy) for the graphing. I have set this to run as a cronjob every 5 minutes.
Seeing as this post is now on reddit and is getting quite a bit of attention, my ISP is TalkTalk and this is their business fibre service.
Here is an example of the graph.
It looks pretty spikey because of the times its running.
You can see quite clearly the peaks and troughs as my ISP hits peak time in the longer duration graph:
This is meant to be an 80 down 20 up service. My automated speedtest quite clearly shows im no getting it all that often. Especially during peak.
The Script
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/jon
OUTPUT="$(speedtest-cli --simple | awk -F: '{ print $2 }' | awk '{sub(/^[ \t]+/, ""); print}')"
PING="$(echo "${OUTPUT}" | awk ' NR==1' | cut -d " " -f1)"
DOWNLOAD="$(echo "${OUTPUT}" | awk ' NR==2' | cut -d " " -f1)"
UPLOAD="$(echo "${OUTPUT}" | awk ' NR==3' | cut -d " " -f1)"
echo "test.ping ${PING} `date +%s`" | nc -q0 192.168.0.175 2003
echo "test.download ${DOWNLOAD} `date +%s`" | nc -q0 192.168.0.175 2003
echo "test.upload ${UPLOAD} `date +%s`" | nc -q0 192.168.0.175 2003
Again, its not pretty, but it certainly does the job.
This is the cronjob thats running it:
*/5 * * * * /home/jon/download-tester.sh >/dev/null 2>&1
Thats it.
Tiny little update. This is how the graph will look in Grafana: