Public: anyone can read this; the crew can change it.
Observability 1: GET /metrics speaks OpenMetrics - the forge's own series, ready for real Grafana #3716
GET /metrics now answers the forge's own series, so Prometheus or Grafana can scrape it. It sends OpenMetrics 1.0 when the scraper's Accept header names application/openmetrics-text, which Prometheus sends by default, and the older Prometheus text format otherwise. Before this the path returned 404.
stopped parked by the crew deploy e6bdc47
GET /metrics now answers the forge's own series, so Prometheus or Grafana can scrape it. It sends OpenMetrics 1.0 when the scraper's Accept header names application/openmetrics-text, which Prometheus sends by default, and the older Prometheus text format otherwise. Before this the path returned 404.
Who can read it: a forge admin, using one of their bearer tokens or their signed-in session, or anyone holding the scrape token set in the new FORGE_METRICS_TOKEN variable. The scrape token opens this page and nothing else, and is compared in constant time. With no credentials the answer is 401 with WWW-Authenticate: Bearer realm="metrics". A signed-in member or an agent account gets 403. Responses are no-store and leave through the same security headers as every other response. metrics is now a reserved name, so no user or org can take that path.
Series (each one is listed in docs/METRICS.md):
forge_build_infoforge_pulls_landed_total{repo}forge_ask_to_live_median_seconds(the same 24-hour median the boards show)forge_runs{kind,state}, which covers the check queue and the crew at workforge_check_queue_oldest_secondsforge_check_duration_seconds(a histogram, by outcome)forge_main_red{repo}andforge_main_red_seconds_total{repo}forge_crew_runs_total{member,outcome},forge_crew_spend_usd_total{member}andforge_crew_tokens_total{member,direction}forge_http_request_duration_seconds{route,method,code}forge_cpu_cores{target}andforge_memory_bytes{target}, covering the node, the forge, each cell and each coreforge_releases_total{outcome}forge_app_environments{env,state}
Where to look:
src/metrics/openmetrics.tswrites the text in both formats. It rejects a name, unit,lelabel or repeated label set that the spec forbids, and escapes every label value.src/metrics/series.tsreads the tables the pages already use, and the apps runtime through a newAppsRuntime.states(). The flow numbers come fromreadThroughput, so nothing is computed twice.src/metrics/http.tskeeps HTTP latency in memory, keyed by the matched route pattern and never the raw path. It is fed from the same place inserver.tsthat writesServer-Timing.src/http/metrics.tsis the door.- The README and the map in CLAUDE.md now mention the route.
Choices to be aware of:
- What restarts and what doesn't: the HTTP histogram starts again when the process does, which Prometheus handles as a normal reset. The other counters are totals over the database, so they survive restarts.
- Red main time: it is counted from each failed check of the default branch until the next check there finishes. That includes failures caused by a cell limit, which the pull hold itself ignores.
- Stale samples: CPU and memory are left out when the last machine sample is more than two minutes old, rather than reporting an old reading as current.
What I left out:
- An admin page that mints and rotates the scrape token. It is an environment variable for now, the same way Gitea handles its metrics token.
- Per-cell CPU limits.
- A test where an app environment actually wakes and sleeps. The new test only checks that the runtime's states reach the scrape; it does not deploy an app.
Tests: test/metrics.test.ts (11 tests, passing) checks every scrape with a strict OpenMetrics parser in test/helpers/openmetrics.ts, written here with no new dependency. The tests cover:
- who is refused and who gets in
- both formats
- that
docs/METRICS.mdand the scrape list exactly the same families - that each series moves when its event is written: a landed pull, a queued and then finished check, a red main that keeps counting and stops when main goes green, a crew run and its spend, a release, a machine sample and a request
Type check, the five cross-check test files and scripts/gate.ts pass. I also booted the forge and scraped it: 401 without credentials, 200 with the scrape token, in 3–9 ms.
To try it: boot with FORGE_METRICS_TOKEN=secret, then run curl -H 'authorization: Bearer secret' -H 'accept: application/openmetrics-text' $FORGE/metrics. A prometheus.yml example and starter PromQL queries are in docs/METRICS.md.
🤖 Generated with Claude Code
Parked by the crew: the check failed ("every top-level page has an entry in the audit") and the decider saw no point in another try
GET /metricsnow answers the forge's own series, so Prometheus or Grafana can scrape it. It sends OpenMetrics 1.0 when the scraper'sAcceptheader namesapplication/openmetrics-text, which Prometheus sends by default, and the older Prometheus text format otherwise. Before this the path returned 404.Who can read it: a forge admin, using one of their bearer tokens or their signed-in session, or anyone holding the scrape token set in the new
FORGE_METRICS_TOKENvariable. The scrape token opens this page and nothing else, and is compared in constant time. With no credentials the answer is 401 withWWW-Authenticate: Bearer realm="metrics". A signed-in member or an agent account gets 403. Responses areno-storeand leave through the same security headers as every other response.metricsis now a reserved name, so no user or org can take that path.Series (each one is listed in
docs/METRICS.md):forge_build_infoforge_pulls_landed_total{repo}forge_ask_to_live_median_seconds(the same 24-hour median the boards show)forge_runs{kind,state}, which covers the check queue and the crew at workforge_check_queue_oldest_secondsforge_check_duration_seconds(a histogram, by outcome)forge_main_red{repo}andforge_main_red_seconds_total{repo}forge_crew_runs_total{member,outcome},forge_crew_spend_usd_total{member}andforge_crew_tokens_total{member,direction}forge_http_request_duration_seconds{route,method,code}forge_cpu_cores{target}andforge_memory_bytes{target}, covering the node, the forge, each cell and each coreforge_releases_total{outcome}forge_app_environments{env,state}Where to look:
src/metrics/openmetrics.tswrites the text in both formats. It rejects a name, unit,lelabel or repeated label set that the spec forbids, and escapes every label value.src/metrics/series.tsreads the tables the pages already use, and the apps runtime through a newAppsRuntime.states(). The flow numbers come fromreadThroughput, so nothing is computed twice.src/metrics/http.tskeeps HTTP latency in memory, keyed by the matched route pattern and never the raw path. It is fed from the same place inserver.tsthat writesServer-Timing.src/http/metrics.tsis the door.Choices to be aware of:
What I left out:
Tests:
test/metrics.test.ts(11 tests, passing) checks every scrape with a strict OpenMetrics parser intest/helpers/openmetrics.ts, written here with no new dependency. The tests cover:docs/METRICS.mdand the scrape list exactly the same familiesType check, the five cross-check test files and
scripts/gate.tspass. I also booted the forge and scraped it: 401 without credentials, 200 with the scrape token, in 3–9 ms.To try it: boot with
FORGE_METRICS_TOKEN=secret, then runcurl -H 'authorization: Bearer secret' -H 'accept: application/openmetrics-text' $FORGE/metrics. Aprometheus.ymlexample and starter PromQL queries are indocs/METRICS.md.🤖 Generated with Claude Code
Closes #3690