Skip to content

Commit 02671f7

Browse files
committed
Initial commit
0 parents  commit 02671f7

23 files changed

Lines changed: 2424 additions & 0 deletions

.gitattributes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Set default behavior to automatically normalize line endings
2+
* text=auto
3+
4+
# Force bash scripts to use LF line endings
5+
*.sh text eol=lf
6+
7+
# Force web assets to be recognized as text
8+
*.php text
9+
*.js text
10+
*.css text
11+
*.sql text
12+
*.md text
13+
14+
# Binary files
15+
*.png binary
16+
*.jpg binary
17+
*.jpeg binary
18+
*.gif binary
19+
*.ico binary

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Database config
2+
includes/db.php
3+
4+
# IDEs
5+
.idea/
6+
.vscode/
7+
*.swp
8+
*.swo
9+
10+
# OS files
11+
.DS_Store
12+
Thumbs.db
13+
14+
# Logs
15+
*.log
16+
17+
# Temporary files
18+
/tmp/
19+
*.tmp
20+
*.temp
21+
22+
# Junie
23+
.junie/

CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing to Gateway Monitor
2+
3+
First off, thank you for considering contributing to Gateway Monitor! It's people like you that make Gateway Monitor such a great tool.
4+
5+
## How Can I Contribute?
6+
7+
### Reporting Bugs
8+
* Check the existing issues to see if the bug has already been reported.
9+
* If not, open a new issue. Include a clear title and description, as much relevant information as possible, and a code sample or a test case demonstrating the expected behavior that is not occurring.
10+
11+
### Suggesting Enhancements
12+
* Open a new issue with a clear title and description of the suggestion.
13+
* Explain why this enhancement would be useful to most Gateway Monitor users.
14+
15+
### Pull Requests
16+
* Fork the repo and create your branch from `master`.
17+
* If you've added code that should be tested, add tests.
18+
* If you've changed APIs, update the documentation.
19+
* Ensure the test suite passes.
20+
* Make sure your code follows the existing style (PSR-12 for PHP, ES6 for JS).
21+
22+
## License
23+
By contributing, you agree that your contributions will be licensed under its MIT License.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Gateway Monitor Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# Gateway Monitor
2+
3+
![Dashboard Overview](assets/img/dashboard_overview.png)
4+
5+
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.
6+
7+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8+
9+
## Features
10+
- **Latency Monitoring**: Continuous tracking of network health using `mtr` (My Traceroute).
11+
- **Bufferbloat Tracking**: Integrated Ookla Speedtest to measure how your connection handles heavy load.
12+
- **Dynamic Host Management**: Add, rename, or delete gateways (WANs) directly from the web dashboard.
13+
- **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).
14+
- **Comparison Visualizations**: Side-by-side charts for multiple connections with smart `(LOADED)` tooltip indicators.
15+
- **Speed & Bloat Analytics**: Combined visualization of download speed, upload speed, and added latency on a single timeline.
16+
- **Bufferbloat Grading System**: Automated scoring (A+ to F) based on added latency, calibrated for competitive gaming standards.
17+
- **CSV Export**: Comprehensive export options for individual or combined datasets, now including a hop-specific filter for MTR data.
18+
- **Mobile Responsive**: Clean, modern dashboard built with Bootstrap 5 and Chart.js.
19+
20+
## Security Recommendations
21+
22+
- **API Keys**: Keep your gateway API keys private. They are required for nodes to ingest data.
23+
- **Maintenance Script**: The `api/maintenance.php` script 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.
24+
- **Database Access**: Ensure your `includes/db.php` is not accessible from the web (it is excluded by `.gitignore`, but double-check your web server configuration).
25+
26+
## Architecture
27+
28+
The system uses a **Centralized Server** and multiple **Remote Nodes**:
29+
1. **Central Server**: Hosts the MySQL database and the PHP-based web dashboard.
30+
2. **Remote Nodes**: Any Linux machine (Ubuntu/Debian recommended) connected to a gateway you want to monitor. These run the collection scripts via `cron`.
31+
32+
## Installation & Setup
33+
34+
### 1. Server Setup (Ubuntu/Debian)
35+
36+
#### A. Install LAMP Stack
37+
Ensure your server has Apache, MySQL, and PHP 8.1+ installed.
38+
```bash
39+
sudo apt update
40+
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php
41+
```
42+
43+
#### B. Database Initialization
44+
1. Log into MySQL and create the database:
45+
```sql
46+
CREATE DATABASE gateway_monitor;
47+
```
48+
2. Import the schema:
49+
```bash
50+
mysql -u root -p gateway_monitor < sql/schema.sql
51+
```
52+
53+
#### C. Web Files
54+
1. Clone or copy this repository to `/var/www/html/gateway_monitor`.
55+
2. Configure database access:
56+
```bash
57+
cp includes/db.php.example includes/db.php
58+
nano includes/db.php
59+
```
60+
*Update the host, database name, user, and password.*
61+
62+
### 2. Dashboard Configuration
63+
64+
1. Open the dashboard in your browser (e.g., `http://your-server/gateway_monitor`).
65+
2. Click the **"Hosts"** button (CPU icon) in the navbar.
66+
3. **Add your Gateways**: Enter a name for each WAN connection (e.g., "Starlink", "Fiber Backup").
67+
4. **Copy API Keys**: Once added, each host will have a unique API Key. You will need these for the remote nodes.
68+
5. **Configure Views**: Use the dropdowns in the navbar to switch between latency metrics, specific hops, and speed test history.
69+
6. (Optional) Click **"Settings"** (Gear icon) to adjust global defaults like the default dashboard metric, test interval, and data retention.
70+
71+
### 3. Remote Node Setup (On each WAN)
72+
73+
On the machine physically connected to the WAN you want to monitor:
74+
75+
#### A. Install Dependencies
76+
```bash
77+
# Install MTR and Curl (Requires mtr 0.93+ for JSON support)
78+
sudo apt install mtr-tiny curl
79+
80+
# Install Official Ookla Speedtest CLI (Required for JSON output)
81+
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
82+
sudo apt install speedtest
83+
```
84+
85+
#### B. Configure Scripts
86+
1. Copy `scripts/monitor.sh` and `scripts/speedtest.sh` to the remote machine.
87+
2. Make them executable: `chmod +x *.sh`.
88+
3. Edit the configuration at the top of both scripts:
89+
* `API_URL`: The URL to your server's API folder (e.g., `http://1.2.3.4/gateway_monitor/api`).
90+
* `API_KEY`: The unique key you copied from the dashboard for **this specific host**.
91+
92+
#### C. Schedule Cron Jobs
93+
Run `crontab -e` and add:
94+
```bash
95+
# Run Latency Monitor every minute
96+
* * * * * /path/to/monitor.sh
97+
98+
# Run Bufferbloat Controller every minute (Smart Scheduling)
99+
* * * * * /path/to/speedtest.sh
100+
```
101+
102+
---
103+
104+
## Detailed Usage
105+
106+
### Managing Speedtest Servers
107+
Accuracy in Bufferbloat testing depends on using a reliable nearby server.
108+
- **Global Default**: Set in the "Settings" modal. Used by all hosts if they don't have a specific ID set.
109+
- **Per-Host Override**: Set in the "Manage Gateways" modal. Ideal if your gateways are in different geographic regions or use different ISPs.
110+
- *Find Server IDs at: [speedtest.net/performance/servers](https://www.speedtest.net/performance/servers)*
111+
112+
### Smart Scheduling
113+
The `speedtest.sh` script runs every minute but only executes a test when instructed by the API.
114+
- The API follows the `speedtest_interval` (default 60 mins).
115+
- To bypass the timer and test immediately, run: `./scripts/speedtest.sh --force`.
116+
117+
### Bufferbloat Grading & Load Detection
118+
![Bufferbloat Grades](assets/img/bufferbloat_grades.png)
119+
*Note: Place your screenshots in `assets/img/` with the filenames shown above to display them in this README.*
120+
121+
The app measures **"Added Latency"** (Loaded Latency - Idle Latency). To keep graphs clean, visual shading has been replaced with smart markers and tooltips:
122+
- **Orange Vertical Lines**: These mark the exact time a Speedtest was performed on any WAN connection.
123+
- **(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.
124+
125+
### Raw Data Exploration & Export
126+
![Raw Data Tabs](assets/img/raw_data_tabs.png)
127+
Below the chart, two tabs provide granular access to your data:
128+
- **MTR Raw Data**: Shows every hop for every MTR run. Includes filters for specific Hosts and Hops.
129+
- **Speed Test History**: Shows full details of every speed test, including raw latencies and Jitter.
130+
- **Consolidated Exports**: Each tab features a "Download CSV" button that respects your active filters (Time, Host, and Hop).
131+
132+
#### Scoring Tiers:
133+
- **A+ (< 2ms)**: Perfect. Zero perceptible delay under load.
134+
- **A (< 10ms)**: Competitive. Ideal for pro gaming.
135+
- **B (< 25ms)**: Solid. Great for casual gaming.
136+
- **C (< 50ms)**: Fair. Noticeable "muddy" feeling.
137+
- **D (< 100ms)**: Poor. Significant lag spikes.
138+
- **F (> 100ms)**: Unplayable.
139+
140+
### Maintenance
141+
The system includes an automatic cleanup mechanism:
142+
- **Data Retention**: Set in the "Settings" modal (default 30 days).
143+
- **Auto-Pruning**: The API automatically deletes records older than the retention period to keep the database lean and the dashboard fast.
144+
145+
---
146+
147+
## Understanding Metrics
148+
- **Average (Avg)**: The mean latency. Good for general health.
149+
- **Worst**: The highest latency recorded. Critical for identifying lag spikes.
150+
- **StDev (Standard Deviation)**: Measures jitter. High StDev means an unstable connection.
151+
- **Packet Loss (%)**: Percentage of packets that never returned.
152+
- **Bufferbloat (Added Latency)**: The extra delay introduced when your connection is under heavy load. Measured in ms.
153+
- **Speed Test (Mbps)**: Real-world bandwidth for Download and Upload. These are displayed together on a single graph for easier comparison.
154+
155+
## Troubleshooting
156+
- **No Data on Charts**:
157+
1. Run `./scripts/monitor.sh` manually on the remote node.
158+
2. Check for errors like "mtr: command not found" or "Unauthorized".
159+
3. Ensure `mtr` version 0.93+ is installed (`mtr --version`). Older versions do not support the `--json` flag.
160+
4. If using an older OS, you may need to compile `mtr` from source or use a newer repository.
161+
- **Speedtest Fails**:
162+
1. Run `./scripts/speedtest.sh --force` manually.
163+
2. Ensure the official Ookla Speedtest CLI is installed, NOT the `speedtest-cli` python package.
164+
3. Verify your API Key and `API_URL` are correct in the script.
165+
- **Permission Denied**:
166+
1. Ensure the scripts are executable: `chmod +x scripts/*.sh`.
167+
2. Some systems require `sudo` for `mtr` if not correctly configured with capabilities. If so, update your crontab to use `sudo`.
168+
169+
## Verifying the Installation
170+
1. **Check API**: Run `./scripts/speedtest.sh --force` manually on a node. It should report "Ingestion complete."
171+
2. **Check Database**:
172+
```sql
173+
SELECT name, last_speed_test FROM hosts;
174+
```
175+
3. **Check Dashboard**: Open `index.php`. You should see the chart and Bufferbloat Report Card.
176+
177+
---
178+
179+
## Contributing
180+
181+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
182+
183+
## License
184+
185+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)