Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
src/live-metrics.ts: rolling timings with p50/p95, counters and gauges, rendered as Prometheus text - one new module and its test #200
I added LiveMetrics in Software/so101/src/live-metrics.ts with its test in src/live-metrics.test.ts. I didn't run bun x tsc --noEmit: both it and bun install fail here with a read-only tempdir error. bun test src/live-metrics.test.ts passes (5 tests), and the forge's check will type-check the pushed code.
stopped parked by the crew
3 earlier comments
I added LiveMetrics in Software/so101/src/live-metrics.ts with its test in src/live-metrics.test.ts. I didn't run bun x tsc --noEmit: both it and bun install fail here with a read-only tempdir error. bun test src/live-metrics.test.ts passes (5 tests), and the forge's check will type-check the pushed code.
I wrote it fresh rather than reusing #131's version, since that branch isn't in this clone. There is no route, page or forge.json change.
observe(name, ms): keeps the last 256 samples in a fixed ring. It reports p50/p95 (nearest-rank), plus a running count and sum.count(name, n): adds to per-second buckets and reports the rate over the last 60 s. A burst rolls off once it is older than the window.gauge(name, v): keeps the last value.snapshot(),prometheus(),summaryLine():snapshot()returns plain data.prometheus()renders timings as summaries withquantile="0.5"andquantile="0.95"plus_sumand_count. Counters render as<name>_per_second.summaryLine()is a one-line text form.- Names and labels: a bad metric or label name throws, and so does a non-finite value. Label values are escaped for backslash, quote and newline.
- Additions beyond the issue: each call takes an optional labels object. The constructor takes an optional clock so tests can move time.
The tests cover 10/200 ms timings giving the right p50/p95, the ring dropping old samples, counters rolling off after the window, bad names throwing, and every non-comment prometheus() line matching name{labels} value.
🤖 Generated with Claude Code
This pull adds LiveMetrics in src/live-metrics.ts with its test in src/live-metrics.test.ts, and the preview's one failing test is not caused by it. I couldn't run tsc here (bun install fails on a read-only tempdir), so the forge's check is the first type check.
What it does:
observekeeps the last 256 timings and reports p50/p95.countgives a per-second rate over the last 60 s, and counts roll off after that.gaugekeeps the last value.snapshot,prometheusandsummaryLinerender them.- Names are checked against
[a-z_][a-z0-9_]*and label values are escaped. - There are no routes, no page changes, and
forge.jsonis untouched. bun test src/live-metrics.test.tspasses (5 tests).
The failing test: "viewer page > a first visit downloads under 51.2 KB gzipped" in src/server.test.ts fails at 51,252 bytes against a 51,200 limit. It fails the same way after merging current main (1e81d4c) into this branch, so main is already 52 bytes over. This pull adds no page or module, so I left the page and the limit alone. Someone needs to either trim about 52 gzipped bytes from the up-front page or modules, or raise the limit deliberately. Until then every pull's preview will report this failure.
This push only merges main into the branch.
🤖 Generated with Claude Code
My two files are done and bun test src/live-metrics.test.ts passes (5 tests). The pull's check still fails on a test I didn't touch, and I haven't pushed anything new.
The failure: "viewer page > a first visit downloads under 51.2 KB gzipped" in src/server.test.ts is over its limit on main itself. The first-visit download was 51,252 bytes against a 51,200 limit with main at 1e81d4c. I merged current main (48b63e8) into the branch locally and it is now 51,743 bytes, because #177 and #181 each added to the page. This pull adds only src/live-metrics.ts and src/live-metrics.test.ts and changes neither the page nor its modules.
Why I left it: the only ways to pass are to trim roughly 550 gzipped bytes from the page or its up-front modules, or to raise the limit. Both change the viewer and need a decision from a person. They don't belong in a pull that is meant to be two new files.
What's needed: an issue or pull that gets main back under 51.2 KB, or one that raises the limit on purpose. Once that lands, this pull's check should pass. The merge of main I made locally is not pushed.
🤖 Generated with Claude Code
Parked by the crew: the check stayed red through 2 automatic tries
I added
LiveMetricsinSoftware/so101/src/live-metrics.tswith its test insrc/live-metrics.test.ts. I didn't runbun x tsc --noEmit: both it andbun installfail here with a read-only tempdir error.bun test src/live-metrics.test.tspasses (5 tests), and the forge's check will type-check the pushed code.I wrote it fresh rather than reusing #131's version, since that branch isn't in this clone. There is no route, page or
forge.jsonchange.observe(name, ms): keeps the last 256 samples in a fixed ring. It reports p50/p95 (nearest-rank), plus a running count and sum.count(name, n): adds to per-second buckets and reports the rate over the last 60 s. A burst rolls off once it is older than the window.gauge(name, v): keeps the last value.snapshot(),prometheus(),summaryLine():snapshot()returns plain data.prometheus()renders timings as summaries withquantile="0.5"andquantile="0.95"plus_sumand_count. Counters render as<name>_per_second.summaryLine()is a one-line text form.The tests cover 10/200 ms timings giving the right p50/p95, the ring dropping old samples, counters rolling off after the window, bad names throwing, and every non-comment
prometheus()line matchingname{labels} value.🤖 Generated with Claude Code
Closes #189