add dashboard

This commit is contained in:
reform
2026-11-01 19:27:26 +03:00
parent f0bc949182
commit 6c22a4e727
2 changed files with 375 additions and 0 deletions
+64
View File
@@ -47,3 +47,67 @@ CAMB_MAIL_READER=/root/camb_code.py
CAMB_KEYS=/opt/camb-shim/camb_keys.json
CAMB_SHIM_PORT=8822
```
## Dashboard
`dashboard.py` — stdlib-only web panel (no CDN, no deps), dark UI, auto-refresh 30s.
```bash
python3 dashboard.py --port 8823 --bank /opt/camb-dash/camb_bank.jsonl \
--stats /opt/camb-dash/camb_stats.json --shim http://127.0.0.1:8822 --refresh 900
```
| route | meaning |
|---|---|
| `GET /` | page: totals + per-account table |
| `GET /api/stats` | JSON snapshot (cached) |
| `GET /api/refresh` | force re-check of the pool |
| `GET /health` | liveness |
What it shows: records / unique accounts / keys / alive / dead, credits left and capacity,
spent, TTS phrases, dubs, USD value, shim health, and a table of accounts with the
last 6 chars of each key and its liveness.
Liveness is checked with `GET https://client.camb.ai/apis/list-voices` + `x-api-key`
(**200 = alive**, 401/403 = dead). It costs **zero credits** — do not use `tts-stream` for health.
Credits cannot be read per API key: `GET /payments/credits/team/<id>` answers `401 Unauthorized`
for an `x-api-key`/Bearer API key (it wants a user JWT). So the panel derives capacity as
`keys * 5000` and subtracts real TTS spends (`tts_credits` in the bank).
Unit file used in production:
```ini
[Unit]
Description=CAMB pool dashboard
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /opt/camb-dash/dashboard.py --port 8823 \
--bank /opt/camb-dash/camb_bank.jsonl --stats /opt/camb-dash/camb_stats.json \
--shim http://127.0.0.1:8822 --refresh 900
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
```
Caddy (behind an existing host, prefix mode — the page uses relative URLs on purpose):
```
redir /camb /camb/ 308
handle_path /camb/* {
reverse_proxy 127.0.0.1:8823
}
```
### Pitfalls
* `--port` overrides env. In the Windows/MSYS shell `VAR=val cmd &` silently loses the
variable, so the panel kept binding its default port; argv is the only reliable path.
* Port 8899 is taken by the ZTE proxy on the workstation — two processes ended up
`LISTEN` on it (SO_REUSEADDR) and every request died as "remote end closed connection".
Pick a port that is really free (`ss -lnt`), not just "looks free".
* `team_id` in the bank can be an int — `str()` it before `.strip()` or the refresh thread dies.