A professional-grade web application to monitor and compare multiple WAN connections. It tracks real-time latency using mtr and monitors Bufferbloat (latency under load) using the official Ookla Speedtest CLI.
- Latency Monitoring: Continuous tracking of network health using
mtr(My Traceroute). - Bufferbloat Tracking: Integrated Ookla Speedtest to measure how your connection handles heavy load.
- Dynamic Host Management: Add, rename, or delete gateways (WANs) directly from the web dashboard.
- Per-Host Configuration: Set individual Speedtest Server IDs for each gateway to ensure the most accurate results for diverse connections (e.g., Fiber vs Starlink).
- Comparison Visualizations: Side-by-side charts for multiple connections with smart
(LOADED)tooltip indicators. - Speed & Bloat Analytics: Combined visualization of download speed, upload speed, and added latency on a single timeline.
- Bufferbloat Grading System: Automated scoring (A+ to F) based on added latency, calibrated for competitive gaming standards.
- CSV Export: Comprehensive export options for individual or combined datasets, now including a hop-specific filter for MTR data.
- Mobile Responsive: Clean, modern dashboard built with Bootstrap 5 and Chart.js.
- API Keys: Keep your gateway API keys private. They are required for nodes to ingest data.
- Maintenance Script: The
api/maintenance.phpscript handles data pruning. For production, it is highly recommended to protect this script with a secret key or restrict access to localhost/trusted IPs to prevent unauthorized database pruning. - Database Access: Ensure your
includes/db.phpis not accessible from the web (it is excluded by.gitignore, but double-check your web server configuration).
The system uses a Centralized Server and multiple Remote Nodes:
- Central Server: Hosts the MySQL database and the PHP-based web dashboard.
- Remote Nodes: Any Linux machine (Ubuntu/Debian recommended) connected to a gateway you want to monitor. These run the collection scripts via
cron.
Ensure your server has Apache, MySQL, and PHP 8.1+ installed.
sudo apt update
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php- Log into MySQL and create the database:
CREATE DATABASE gateway_monitor;
- Import the schema:
mysql -u root -p gateway_monitor < sql/schema.sql
- Clone or copy this repository to
/var/www/html/gateway_monitor. - Configure database access:
Update the host, database name, user, and password.
cp includes/db.php.example includes/db.php nano includes/db.php
- Open the dashboard in your browser (e.g.,
http://your-server/gateway_monitor). - Click the "Hosts" button (CPU icon) in the navbar.
- Add your Gateways: Enter a name for each WAN connection (e.g., "Starlink", "Fiber Backup").
- Copy API Keys: Once added, each host will have a unique API Key. You will need these for the remote nodes.
- Configure Views: Use the dropdowns in the navbar to switch between latency metrics, specific hops, and speed test history.
- (Optional) Click "Settings" (Gear icon) to adjust global defaults like the default dashboard metric, test interval, and data retention.
On the machine physically connected to the WAN you want to monitor:
# Install MTR and Curl (Requires mtr 0.93+ for JSON support)
sudo apt install mtr-tiny curl
# Install Official Ookla Speedtest CLI (Required for JSON output)
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
sudo apt install speedtest- Copy
scripts/monitor.shandscripts/speedtest.shto the remote machine. - Make them executable:
chmod +x *.sh. - Edit the configuration at the top of both scripts:
API_URL: The URL to your server's API folder (e.g.,http://1.2.3.4/gateway_monitor/api).API_KEY: The unique key you copied from the dashboard for this specific host.
Run crontab -e and add:
# Run Latency Monitor every minute
* * * * * /path/to/monitor.sh
# Run Bufferbloat Controller every minute (Smart Scheduling)
* * * * * /path/to/speedtest.shAccuracy in Bufferbloat testing depends on using a reliable nearby server.
- Global Default: Set in the "Settings" modal. Used by all hosts if they don't have a specific ID set.
- Per-Host Override: Set in the "Manage Gateways" modal. Ideal if your gateways are in different geographic regions or use different ISPs.
- Find Server IDs at: speedtest.net/performance/servers
The speedtest.sh script runs every minute but only executes a test when instructed by the API.
- The API follows the
speedtest_interval(default 60 mins). - To bypass the timer and test immediately, run:
./scripts/speedtest.sh --force.
Note: Place your screenshots in assets/img/ with the filenames shown above to display them in this README.
The app measures "Added Latency" (Loaded Latency - Idle Latency). To keep graphs clean, visual shading has been replaced with smart markers and tooltips:
- Orange Vertical Lines: These mark the exact time a Speedtest was performed on any WAN connection.
- (LOADED) Status: When hovering over MTR latency points, the tooltip will display
(LOADED)if that sample was captured during an active speed test. This status is also visible in the MTR Raw Data table. Correlated automatically via timestamps.
Below the chart, two tabs provide granular access to your data:
- MTR Raw Data: Shows every hop for every MTR run. Includes filters for specific Hosts and Hops.
- Speed Test History: Shows full details of every speed test, including raw latencies and Jitter.
- Consolidated Exports: Each tab features a "Download CSV" button that respects your active filters (Time, Host, and Hop).
- A+ (< 2ms): Perfect. Zero perceptible delay under load.
- A (< 10ms): Competitive. Ideal for pro gaming.
- B (< 25ms): Solid. Great for casual gaming.
- C (< 50ms): Fair. Noticeable "muddy" feeling.
- D (< 100ms): Poor. Significant lag spikes.
- F (> 100ms): Unplayable.
The system includes an automatic cleanup mechanism:
- Data Retention: Set in the "Settings" modal (default 30 days).
- Auto-Pruning: The API automatically deletes records older than the retention period to keep the database lean and the dashboard fast.
- Average (Avg): The mean latency. Good for general health.
- Worst: The highest latency recorded. Critical for identifying lag spikes.
- StDev (Standard Deviation): Measures jitter. High StDev means an unstable connection.
- Packet Loss (%): Percentage of packets that never returned.
- Bufferbloat (Added Latency): The extra delay introduced when your connection is under heavy load. Measured in ms.
- Speed Test (Mbps): Real-world bandwidth for Download and Upload. These are displayed together on a single graph for easier comparison.
- No Data on Charts:
- Run
./scripts/monitor.shmanually on the remote node. - Check for errors like "mtr: command not found" or "Unauthorized".
- Ensure
mtrversion 0.93+ is installed (mtr --version). Older versions do not support the--jsonflag. - If using an older OS, you may need to compile
mtrfrom source or use a newer repository.
- Run
- Speedtest Fails:
- Run
./scripts/speedtest.sh --forcemanually. - Ensure the official Ookla Speedtest CLI is installed, NOT the
speedtest-clipython package. - Verify your API Key and
API_URLare correct in the script.
- Run
- Permission Denied:
- Ensure the scripts are executable:
chmod +x scripts/*.sh. - Some systems require
sudoformtrif not correctly configured with capabilities. If so, update your crontab to usesudo.
- Ensure the scripts are executable:
- Check API: Run
./scripts/speedtest.sh --forcemanually on a node. It should report "Ingestion complete." - Check Database:
SELECT name, last_speed_test FROM hosts;
- Check Dashboard: Open
index.php. You should see the chart and Bufferbloat Report Card.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
