Skip to content

karlobrien/bandwidth_monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bandwidth Monitor

A self-hosted bandwidth monitoring application that periodically runs speed tests and displays results on a web dashboard. Built in Go with no external runtime dependencies.

Features

  • Automatic speed tests at configurable intervals
  • Measures download speed, upload speed, and latency
  • Web dashboard with interactive charts
  • Historical data stored in SQLite
  • REST API for programmatic access
  • Single binary deployment
  • Cross-platform (Linux, macOS, Windows, ARM64)

Screenshot

The dashboard displays current speed, historical statistics, and a time-series chart of your connection performance.

Quick Start

Build from source

git clone https://github.com/karlobrien/bandwidth_monitor.git
cd bandwidth_monitor
go build -o bandwidth-monitor .
./bandwidth-monitor

Open http://localhost:8080 in your browser.

Cross-compile for Raspberry Pi

CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bandwidth-monitor-arm64 .

Configuration

Configuration is done via environment variables:

Variable Default Description
PORT 8080 Web server port
TEST_INTERVAL 1h Time between speed tests (e.g., 30m, 2h)
DB_PATH ./bandwidth.db SQLite database file path
RUN_ON_STARTUP true Run a speed test immediately on startup
ADVERTISED_SPEED_MBPS - Your expected speed for comparison

Example:

TEST_INTERVAL=30m PORT=3000 ./bandwidth-monitor

API Endpoints

Endpoint Method Description
/ GET Web dashboard
/health GET Health check (returns ok)
/api/results GET Speed test results (JSON)
/api/stats GET Aggregate statistics (JSON)
/api/test POST Trigger an immediate speed test

Query Parameters

GET /api/results

  • limit - Number of results to return (default: 100)
  • offset - Pagination offset (default: 0)

Example API Usage

# Get recent results
curl http://localhost:8080/api/results?limit=10

# Get statistics
curl http://localhost:8080/api/stats

# Trigger a speed test
curl -X POST http://localhost:8080/api/test

Deployment

Raspberry Pi with systemd

  1. Copy the binary to your Pi:
scp bandwidth-monitor-arm64 user@pi:~/bandwidth-monitor/bandwidth-monitor
  1. Copy the service file:
scp bandwidth-monitor.service user@pi:~/
  1. On the Pi, install and enable the service:
chmod +x ~/bandwidth-monitor/bandwidth-monitor
sudo mv ~/bandwidth-monitor.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable bandwidth-monitor
sudo systemctl start bandwidth-monitor
  1. Check status:
sudo systemctl status bandwidth-monitor
journalctl -u bandwidth-monitor -f

Docker (optional)

FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -o bandwidth-monitor .

FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/bandwidth-monitor .
EXPOSE 8080
CMD ["./bandwidth-monitor"]

Architecture

bandwidth_monitor/
├── main.go              # Application entry point
├── config/              # Configuration loading
├── speedtest/           # Speed test execution (uses speedtest.net)
├── scheduler/           # Periodic test scheduling
├── storage/             # SQLite database operations
└── web/                 # HTTP server and dashboard
    └── templates/       # HTML dashboard template

How It Works

  1. On startup, the application initializes a SQLite database and starts a scheduler
  2. The scheduler triggers speed tests at the configured interval
  3. Each test selects the best server from 5 candidates based on latency
  4. Results (download, upload, latency) are stored in the database
  5. The web dashboard fetches and displays data via the REST API

Tech Stack

  • Language: Go
  • Database: SQLite (pure-Go driver, no CGO)
  • Speed Test: speedtest-go library
  • Frontend: Vanilla HTML/CSS/JavaScript with Chart.js

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors