cake-stats

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 16 Imported by: 0

README

cake-stats

Real-time web UI for monitoring CAKE SQM (Smart Queue Management) statistics on Linux/OpenWrt routers.


Table of Contents

How it looks like

Desktop

Web UI preview
UI for desktop screens

Web UI preview
Graphs for desktop screens

Mobile

Web UI preview
UI for mobile screens

Web UI preview
Graphs for mobile screens

↑ Back to Table of Contents

Status

  • Stable — all parser unit tests passing, binary builds clean for 14 target platforms.

↑ Back to Table of Contents

Features

  • Automatically discovers all CAKE qdiscs via tc -s qdisc
  • Parses every CAKE field: thresh, target, interval, pk_delay, av_delay, sp_delay, backlog, pkts, bytes, way_inds, way_miss, way_cols, drops, marks, ack_drop, sp_flows, bk_flows, un_flows, max_len, quantum
  • Correctly handles diffserv modes: diffserv3, diffserv4, diffserv8, besteffort, precedence; also parses the separate fwmark MASK tin-override parameter
  • Two-word tier names are joined correctly (e.g. "Best Effort")
  • Real-time push via Server-Sent Events — no WebSocket, no polling jitter
  • Single static binary — no runtime dependencies; runs on OpenWrt with ≈4 MB of RAM overhead
  • Web UI: dark TUI aesthetic (#2D3C59 bg, JetBrains Mono, zero hover animations)
  • Responsive for desktop and mobile (sticky first column, horizontal scroll on small screens)
  • Per-interface live sparklines (TX throughput, avg latency, drops/s) with current-value labels
  • Tap/click any sparkline bar to open a full-screen history modal with three uPlot time-series charts
  • Server-side ring buffer retains history across page reloads (configurable via -history flag)

↑ Back to Table of Contents

Requirements

  • Linux kernel with tc + sch_cake module loaded, or OpenWrt with kmod-sched-cake
  • Go 1.22+ (build only; not needed at runtime)

↑ Back to Table of Contents

Build

git clone https://github.com/galpt/cake-stats
cd cake-stats
go test ./...          # should print PASS
go build -o cake-stats .

Cross-compile for a MIPS OpenWrt router:

CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat \
  go build -ldflags "-s -w" -o cake-stats-linux-mips .

Pre-built binaries for all common platforms are attached to every GitHub Release.

↑ Back to Table of Contents

Usage

Quick start
./cake-stats                 # serves on http://0.0.0.0:11112
./cake-stats -port 8080      # custom port
./cake-stats -interval 2s    # poll tc every 2 seconds (default 1s)
./cake-stats -history 3600   # retain 1 hour of history (default 300 = 5 min)
./cake-stats -host 127.0.0.1 # listen only on loopback
./cake-stats -version        # print version and exit

Open http://<router-ip>:11112 in a browser.

Install on OpenWrt
sh install.sh                # auto-detects arch, downloads latest binary
sh install.sh --port 11112 --interval 1s
Install on systemd Linux
sudo sh install.sh
Uninstall
sh uninstall.sh              # prompts for confirmation
sh uninstall.sh --force      # no prompts
API
Endpoint Description
GET / Web UI (HTML)
GET /api/stats Current stats snapshot (JSON)
GET /api/history Full ring-buffer history per interface (JSON), used to seed sparklines on page load
GET /events SSE stream — emits updated JSON on every poll interval

↑ Back to Table of Contents

Design Notes

  • Pure stdlib Go: no external dependencies; the binary embeds index.html via //go:embed.
  • SSE over WebSocket: server-to-client only push makes SSE sufficient and simpler; browsers handle automatic reconnection.
  • uint64 for all counters: avoids overflow for high-throughput links; max ~18.4 EB.
  • sync.RWMutex: a single reader/writer lock separates the poller goroutine from concurrent HTTP handlers.
  • Delay fields as strings: pk_delay, av_delay, sp_delay are kept as raw strings (e.g., "6.73ms") so the unit suffix is preserved.
  • Ring-buffer history: HistoryStore allocates a fixed-size ring per interface at startup; memory is bounded by capacity × interfaces × ~40 B and never grows. Configurable via -history N (default 300 samples ≈ 5 min at 1 s interval).
  • Sparklines: pure SVG polylines drawn in-place inside stable DOM nodes so the per-second innerHTML swap of the stats table does not affect them. uPlot (CDN) is used only for the full-screen history modal.

↑ Back to Table of Contents

Limitations & Next Steps

  • No authentication; if exposing to the internet, put behind a reverse proxy with basic auth.
  • Windows/FreeBSD builds are provided but CAKE is a Linux-only qdisc.

↑ Back to Table of Contents

Contributing

go test ./...    # run unit tests
go vet ./...     # static analysis

PRs welcome. Please keep external dependencies at zero.

↑ Back to Table of Contents

License

MIT

↑ Back to Table of Contents

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL