Skip to content

About

Phone-friendly dashboard for the 8-Spark cluster's per-user usage (requests, tokens, who's active)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

spark-usage-web

A one-file, phone-friendly dashboard for the 8-Spark cluster's per-user usage — who is talking to the model right now, how many requests each person has made, and how many tokens they have burned.

phone preview

It has no dependencies (Python standard library only) and no cloud component. It re-renders the usage service's own dashboard as a mobile page.


What it shows

  • Active right now — every request currently in flight, and who made it.
  • Who is using it — one card per person: requests in the last 5 min / 1 h / 24 h, total tokens, errors, and when they were last seen, sorted by activity.
  • Recent requests — the last dozen requests, newest first.
  • Server signals — anything numeric the usage service reports about the server itself (e.g. running / waiting request counts), if present.
  • Header pills with cluster totals: active now, req/5m, req/1h, tokens.

The page auto-refreshes every 5 seconds (and pauses when the phone screen is off), with a manual Refresh button.


Where the data comes from

Spark 1 runs spark-usage.service: an aiohttp proxy that records, per request, the user, model, timestamps, state, HTTP status and token counts — never prompt or response text — into a SQLite database, and exposes a dashboard on loopback :4002.

The tower already reaches that dashboard through the existing spark-monitor-tunnel.service (an ssh -L 4002:127.0.0.1:4002 tunnel to [email protected]).

This script simply reads http://127.0.0.1:4002/stats from the tower and serves a nicer, phone-sized view on the LAN. It does not need a key to Spark 1 and it never stores anything.

 phone ──HTTP──▶ tower :8080 ──▶ 127.0.0.1:4002 (existing SSH tunnel) ──▶ Spark 1 usage DB

Quick start (on the tower)

# 1. get the file
git clone https://github.com/jonbotx/spark-usage-web.git
cd spark-usage-web

# 2. try it immediately with fake data (no cluster needed)
python3 spark-usage-web.py --demo

Now open http://<tower-ip>:8080 on your phone (find the tower IP with hostname -I). You should see the demo dashboard.

# 3. when you like it, serve the real thing
python3 spark-usage-web.py

The real mode needs the usage tunnel to be up:

systemctl --user status spark-monitor-tunnel.service   # should be active
curl -s http://127.0.0.1:4002/stats | head -c 200      # should be JSON

If /stats is empty or 404, tell me — the usage service's schema may differ from what this tool assumes (see If the data looks wrong below).

Install as a service (starts at boot)

./install.sh

install.sh copies the script to ~/spark-usage-web/, writes a systemd --user unit, and enables + starts it. To keep it running after you log out, make sure lingering is on (it already is if the tunnel service survives):

loginctl enable-linger "$USER"

Options

Flag Default Meaning
--listen HOST:PORT 0.0.0.0:8080 where to serve the page
--upstream URL http://127.0.0.1:4002/stats the usage stats JSON endpoint
--interval SECONDS 5 browser auto-refresh interval
--demo off serve synthetic data (no upstream needed)
--probe — print the upstream JSON shape and exit
--once — fetch + normalize + print JSON, then exit

Environment overrides used by install.sh: PORT, LISTEN, UPSTREAM, DIR.


If the data looks wrong

The usage service is custom, so this tool is built to be forgiving: it looks for a generous set of field-name spellings (user / api_user / identity, …, prompt_tokens / input_tokens, …), understands both per-request event rows and per-user aggregate rows, and merges them sensibly. It also never prints anything that looks like a bearer key.

If a section is empty or a number looks off, run:

python3 spark-usage-web.py --probe

and send me the output — it prints the top-level keys, a sample record, and what the normalizer detected. A one-line fix will make it exact.

You can also open /api/raw in the browser (or tap raw data at the bottom of the page) to see exactly what the upstream returned.


Troubleshooting

  • Red "Cannot read usage data" box — the tunnel is down or the path is wrong. Check systemctl --user status spark-monitor-tunnel.service and curl -s http://127.0.0.1:4002/stats.
  • Address already in use — something else is on 8080; use --listen 0.0.0.0:8090.
  • Can't reach it from the phone — confirm you used the tower's LAN IP, that the phone is on the same network (or VPN), and that a host firewall isn't blocking the port.
  • Page shows "DEMO DATA" — you're running with --demo.

Privacy & security

  • Only metadata is shown: user, request counts, token counts, status. The usage service deliberately stores no prompt or response text.
  • The page has no authentication — anyone who can reach the tower port can see the usage numbers. That is fine on a trusted home LAN. If you want it locked down, bind to a specific address (--listen 192.168.0.223:8080) or put it behind a reverse proxy with auth.
  • Bearer keys are never displayed; anything that looks like a key is masked.

Files

File Purpose
spark-usage-web.py the whole tool — single file, stdlib only
install.sh install + enable as a systemd --user service
spark-usage-web.service.example the unit install.sh writes
preview/phone-demo.png screenshot of --demo in a phone-sized window

About

Phone-friendly dashboard for the 8-Spark cluster's per-user usage (requests, tokens, who's active)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages