A simple website built with Node.js, Express.js and MySQL / MariaDB to automatically measure your network speeds. The results can then be viewed and filtered on the site in a list or graph format.
Note: This project uses speedtest-net to run the speed tests. When you run the site Ookla's Terms of Use and Privacy Policy are automatically accepted. By running this site you also agree to their terms.
This site requires a MySQL server to be running. I recommend using MariaDB although you can use an alternative. See here for installation instructions or look below for the Linux instructions.
sudo apt -y install mariadb-server
sudo mysql_secure_installation
- Skip root password as none has been set yet.
- Don't set a root password. (reference)
- "y" to accept all default.
sudo mysql
- For initial access. Follow the next step to make an admin account.
Global Admin User Setup
CREATE USER admin@localhost IDENTIFIED BY 'password';
GRANT ALL ON *.* TO admin@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
User & Database Setup
CREATE USER network_monitor@localhost IDENTIFIED BY 'password';
CREATE DATABASE network_monitor;
GRANT ALL PRIVILEGES ON network_monitor.* TO network_monitor@localhost;
USE network_monitor;
CREATE TABLE IF NOT EXISTS speed_tests (
id INT NOT NULL AUTO_INCREMENT,
test_date DATE NOT NULL,
test_time TIME NOT NULL,
ping_speed DECIMAL(5,2) UNSIGNED NOT NULL,
download_speed DECIMAL(5,2) UNSIGNED NOT NULL,
upload_speed DECIMAL(5,2) UNSIGNED NOT NULL,
PRIMARY KEY (id)
);
DESCRIBE speed_tests;
should return:
+----------------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-----------------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| test_date | date | NO | | NULL | |
| test_time | time | NO | | NULL | |
| ping_speed | decimal(5,2) unsigned | NO | | NULL | |
| download_speed | decimal(5,2) unsigned | NO | | NULL | |
| upload_speed | decimal(5,2) unsigned | NO | | NULL | |
+----------------+-----------------------+------+-----+---------+----------------+
- Run
npm install
to setup the project. - Copy
example.config.json
toconfig.json
and edit if necessary. - Build the website with
gulp build
- Use
node app
to run the application.
There are many ways to get the server to run in the background, but I use systemd. The setup is shown below:
sudo vim /lib/systemd/system/network-monitor.service
2 Add the following:
[Unit]
Description=app.js - Website monitoring you network speeds.
Documentation=https://github.com/Ben-Ryder/network-monitor
After=network.target
[Service]
Type=simple
User=pi
ExecStart=/usr/bin/node /home/pi/network-monitor/app.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start network-monitor
sudo systemctl enable network-monitor
- To view status:
sudo systemctl status network-monitor
- To restart:
sudo systemctl restart network-monitor
(See this nodesource.com article for more info.)
All development can be done through the gulp task gulp develop
.
This task bundles:
- broswer-sync refresh for templates & styling.
- nodemon for node server restarting.
- gulp watch for sass changes