One thing you may wish to graph is your internet speed.
Lucky someone has already created a script we can ‘borrow’
Here is the author’s GitHub
The only thing you may wish to change is the DATABASE=”XXXXX” to suit the database you want the script to insert into.
We are going to create another database just for speedtest results.
#!/bin/bash INFLUXDB_HOST="localhost" INFLUXDB_PORT="8086" DATABASE="speedtest" [ -f /etc/default/speedtest_tester ] && . /etc/default/speedtest_tester while [[ $# > 0 ]]; do key="$1" case $key in -p|--port) INFLUXDB_PORT="$2" shift ;; -h|--host) INFLUXDB_HOST="$2" shift ;; --database) DATABASE="$2" shift ;; *) echo "Unknown option $key" ;; esac shift done timestamp=$(date +%s%N) output=$(speedtest-cli --simple) hostname=$(hostname) line=$(echo -n "$output" | awk '/Ping/ {print "ping=" $2} /Download/ {print "download=" $2 * 1000 * 1000} /Upload/ {print "upload=" $2 * 1000 * 1000}' | tr '\n' ',' | head -c -1) curl -XPOST "http://$INFLUXDB_HOST:$INFLUXDB_PORT/write?db=$DATABASE" -d "speedtest,host=$hostname $line $timestamp"
#Sudo nano /etc/default/speedtest_tester.sh
Copy this to your clipboard.
Jump over to a SSH session to your Virtual Machine, and run the following to create a .sh script
To make it executable run this!
#sudo chmod u+x /etc/default/speedtest_tester.sh
We need some further software to actually run the speedtest, obtain that by running:
#sudo apt-get install speedtest-cli
Go to the Influx DB admin page on <YOURSERVERIP>:8083
If you want to keep these results separate to your other Database as mentioned at the start of this article, you can create one now.
Click Query Templates –> Create Database
Change to query to be CREATE DATABASE “speedtest”
Press Enter!
Its time to test if this script is working, run the following command and wait a few moments.
#sudo /etc/default/speedtest_tester.sh
To check it is writing info to Influx, Go to the admin console, ensure you have the ‘speedtest’ database selected and run SHOW MEASUREMENTS, You should see the word speedtest listed.
Now login to Grafana and add a new Datasource.
Name=Speedtest
Default= unchecked
Type= InfluxDB
URL= http://localhost:8086
Database=Speedtest
Now make sure when you press Save and test that it is functioning correctly.
Navigate to an existing Dashboard, or create a new one and select a new graph,
You need to pay attention to where you are getting data from, delete the one that automatically adds,
Select +Add Query from the Panel Data Source when you have the speedtest database selected.
The 3 queries I used are:
SELECT mean(“download”) FROM “speedtest” WHERE “host” = ‘Netmon3’ AND $timeFilter GROUP BY time($interval) fill(null)
SELECT mean(“upload”) FROM “speedtest” WHERE “host” = ‘Netmon3’ AND $timeFilter GROUP BY time($interval) fill(null)
SELECT mean(“ping”) FROM “speedtest” WHERE “host” = ‘Netmon3’ AND $timeFilter GROUP BY time($interval) fill(null)
Make the graph really pretty by selecting bars, and lines under Display. Or not, whatever, you can make it look pretty from here!
SAVE the dashboard now.
Jump back into the SSH Session and lets schedule this with CRON.
#Sudo nano /etc/crontab
Pate the following line at the bottom:
0 * * * * root /etc/default/speedtest_tester.sh
Happy Days!
More to come!
EDIT:
Want to run this Internet Speedtest between certain hours only?
Use this line in the Cron file instead of the one above!
00 9-17/1 * * * root /etc/default/speedtest_tester.sh
EDIT # 2:
CentOS Configuration:
It took me a little longer to get the same script running on CentOS, Put the speedtest.ph and the speedtest_tester.sh file in /usr/local/src/
speedtest.py
speedtest_tester.sh
Change the permissions on the .sh file with the same Chmod command above, updated for the new file location.