feat(pi-durable): scrape the usage sampler and alert on OpenCode Go's allowance (durable-pi-workspace#399) #20

Manually merged
bryan merged 2 commits from p399-3-go-alerts into main 2026-11-11 02:02:05 +00:00
Owner

P399.3 of durable-pi-workspace#399's plan (vault/2026-11-10-opencode-go-usage-from-pi-sessions-plan.md there, mechanism 6).

Changed (modules/services/pi-durable.nix, in the sampler's block, with the monitoring module only):

  • A Prometheus scrape job pi-durable-sampler for 127.0.0.1:<sampler.port>/metrics.
  • Four rules on the OpenCode Go windows the sampler computes from Pi's session records (durable-pi-workspace e108f3b):
    • OpenCodeGoAllowanceHigh (warning): any window's pi_durable_sampler_opencode_go_share >= 0.8 for 5m;
    • OpenCodeGoAllowanceCritical (critical): >= 0.95 for 5m;
    • OpenCodeGoUsageUnreadable (warning): no source readable, a configured directory missing, or a file unreadable, for 30m, each term alone (bad lines left out: Pi skips them too);
    • OpenCodeGoUnknownModel (warning): a model counted at the dearest weight for 1h.
      Each says the OpenCode console is authoritative and what 100% means. They replace Hermes's "Watch OpenCode Go allowance" job and drop its 50% notice.
  • modules/services/AGENTS.md: the sampler's line.

Tests: new scripts/test_opencode_go_alerts.py (14): the scrape and that it follows sampler.port; nothing without the sampler; promtool check metrics on the sampler's Go text; promtool test rules for each rule firing and quiet, 94% not critical, a window dropping back, bad lines alone quiet, the unreadable rule on its own series alone, each rule's severity pinned. Mutations of each threshold, the missing-dirs term, the unknown model's for, the port, a severity and the sum-for-or each fail a test. test_pi_durable_module.py, test_monitoring_content_probes.py, test_pi_bots_service.py and test_dashy_status_api.py pass; darwin-rebuild build --flake .#studio builds.

Review: a visible Pi reviewer (Opus 5.5, medium, work seat) reviewed 392e74a..f2279a1 and approved, with one should-fix (the tests took the expected severity from the rule under test) and one nit (the unreadable rule's sum needed all three series, so the old reader's lone readable 0 raised nothing). It checked promtool check config on Studio's generated prometheus.yml and that /metrics answers loopback without a login. Both fixed in 2ea1670.

After update-system: Prometheus's targets list pi-durable-sampler up; the four rules load with health ok. The share series appear once the sampler runs the new reader (P399.2's commissioning). Then Hermes's watcher is paused.

P399.3 of durable-pi-workspace#399's plan (`vault/2026-11-10-opencode-go-usage-from-pi-sessions-plan.md` there, mechanism 6). **Changed** (`modules/services/pi-durable.nix`, in the sampler's block, with the monitoring module only): - A Prometheus scrape job `pi-durable-sampler` for `127.0.0.1:<sampler.port>/metrics`. - Four rules on the OpenCode Go windows the sampler computes from Pi's session records (durable-pi-workspace `e108f3b`): - `OpenCodeGoAllowanceHigh` (warning): any window's `pi_durable_sampler_opencode_go_share >= 0.8` for 5m; - `OpenCodeGoAllowanceCritical` (critical): `>= 0.95` for 5m; - `OpenCodeGoUsageUnreadable` (warning): no source readable, a configured directory missing, or a file unreadable, for 30m, each term alone (bad lines left out: Pi skips them too); - `OpenCodeGoUnknownModel` (warning): a model counted at the dearest weight for 1h. Each says the OpenCode console is authoritative and what 100% means. They replace Hermes's "Watch OpenCode Go allowance" job and drop its 50% notice. - `modules/services/AGENTS.md`: the sampler's line. **Tests:** new `scripts/test_opencode_go_alerts.py` (14): the scrape and that it follows `sampler.port`; nothing without the sampler; `promtool check metrics` on the sampler's Go text; `promtool test rules` for each rule firing and quiet, 94% not critical, a window dropping back, bad lines alone quiet, the unreadable rule on its own series alone, each rule's severity pinned. Mutations of each threshold, the missing-dirs term, the unknown model's `for`, the port, a severity and the sum-for-`or` each fail a test. `test_pi_durable_module.py`, `test_monitoring_content_probes.py`, `test_pi_bots_service.py` and `test_dashy_status_api.py` pass; `darwin-rebuild build --flake .#studio` builds. **Review:** a visible Pi reviewer (Opus 5.5, medium, work seat) reviewed `392e74a..f2279a1` and approved, with one should-fix (the tests took the expected severity from the rule under test) and one nit (the unreadable rule's sum needed all three series, so the old reader's lone `readable 0` raised nothing). It checked `promtool check config` on Studio's generated `prometheus.yml` and that `/metrics` answers loopback without a login. Both fixed in `2ea1670`. **After `update-system`:** Prometheus's targets list `pi-durable-sampler` up; the four rules load with health ok. The share series appear once the sampler runs the new reader (P399.2's commissioning). Then Hermes's watcher is paused.
P399.3. Prometheus scrapes the Claude usage sampler's loopback /metrics (job
pi-durable-sampler, following sampler.port), and four rules alert on the
OpenCode Go windows the sampler now computes from Pi's session records:
OpenCodeGoAllowanceHigh (80%, warning), OpenCodeGoAllowanceCritical (95%,
critical), OpenCodeGoUsageUnreadable (sources missing or unreadable, 30m)
and OpenCodeGoUnknownModel (1h). They replace Hermes's watcher's alerts.
Tested with promtool on series shaped like the sampler's /metrics.
bryan changed title from feat(pi-durable): scrape the usage sampler and alert on OpenCode Go's allowance (durable-pi-workspace#399) to WIP: feat(pi-durable): scrape the usage sampler and alert on OpenCode Go's allowance (durable-pi-workspace#399) 2026-11-11 01:48:41 +00:00
From the P399.3 review: the expected severity came from the rule under test,
so a wrong one passed; and a sum needed all three series, so the old
reader's lone readable 0 raised nothing. Now each term alone raises it.
bryan changed title from WIP: feat(pi-durable): scrape the usage sampler and alert on OpenCode Go's allowance (durable-pi-workspace#399) to feat(pi-durable): scrape the usage sampler and alert on OpenCode Go's allowance (durable-pi-workspace#399) 2026-11-11 02:01:56 +00:00
bryan manually merged commit e5752e7e77 into main 2026-11-11 02:02:05 +00:00
Sign in to join this conversation.
No reviewers
No labels
ready-for-agent
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bryan/nix-configs!20
No description provided.