Collects up- and downstream speed with speedtest-cli from http://www.speedtest.net to SQLite DB and draws graphs using PHP and JavaScript. It consists of two parts, a Shell script and a PHP script.
- Just for fun
- Archiving results and contact the provider with historical data in the case the bandwidth provided is lower as guaranteed in your contract
Be aware that the speedtest statistics can be inaccurate if some other rather unusal network traffic is going on. Before contacting your ISP, check your network traffic with tools like vnstat and other tools.
- SQLite 3 -> https://www.sqlite.org
- PHP 7 (older probably work as well)
- speedtest-cli -> https://github.com/sivel/speedtest-cli
- Chartjs -> https://www.chartjs.org
The following procedure is for Fedora 29. It may probably work similar with other distributions as well.
dnf -y install python3-speedtest-cli.noarch php php-pdo php-jsonIf you want to have your public IP shown in the output tell SELinux about it. The -P paramter is needed to make it persistent over reboots
setsebool -P httpd_can_network_connect 1Customize and install the shellscript speedtest-collector.sh to a handy place of your choice and add a crontab enty. The customization includes the place where the sqlite database file is located (i.e. /var/www/html/speedtest-collector.db
The following will get you the list of servers, sorted reverse by distance.
speedtest --list|tacPick two servers , one should be in the same AS (autonomous system) as your provider, if possible. The other one should be one not too far away. My output looks as following:
19035) Vodafone Kabel Deutschland (Berlin, Germany) [3.53 km]
17137) Cronon AG (Berlin, DE) [3.53 km]
10259) Interoute VDC (Berlin, Germany) [3.53 km]
6417) SysEleven GmbH (Berlin, Germany) [3.53 km]
1475) IPB GmbH (Berlin, Germany) [1.59 km]
Retrieving speedtest.net configuration...I was picking numbers 19035 (Provider Network) and 1475 (Shortest distance)
Look for the section "Main - Run the tests customize your servers here"
I added the following:
runTest "19035"
sleep 10
runTest "1475"Put the same values in the function getCSVString
sqlite3 /var/www/html/speedtest-collector.dbPopulate the DB with a table
CREATE TABLE IF NOT EXISTS "bandwidth" ("serverid" INTEGER NOT NULL , "sponsor" VARCHAR NOT NULL , "servername" VARCHAR NOT NULL , "times" DATETIME PRIMARY KEY NOT NULL UNIQUE , "distance" FLOAT NOT NULL , "ping" FLOAT NOT NULL , "download" FLOAT NOT NULL , "upload" FLOAT NOT NULL );*/30 * * * * /root/speedtest-collector.shCopy or fetch the script to a useful location, i.e. /var/www/html
wget https://raw.githubusercontent.com/ldelouw/speedtest-statistics/master/speedtest-statistics.php -O /var/www/htmlmkdir /var/www/html/scripts
wget https://www.chartjs.org/dist/2.7.3/Chart.bundle.js -O /var/www/html/scripts/Chart.bundle.js
restorecon -Rv /var/www/html- Add a second graph for the Ping values
- Automatically configure the PHP script according the number of servers in the database (SQL offset etc.)
- Other providers than speedtest.net?
- ~~ Choosing timeframes ~~ This has been implemented in the most recent version
Is welcome
