feat(api): Prometheus metrics; fix(monitors): region limit in the form #172

Merged
Sebi merged 2 commits from feat/api-metrics into main 2026-11-29 11:21:32 +00:00
Owner

Summary

  • New internal/metrics package (client_golang, own registry per instance) and a second listener in cmd/api: UPTIME_API_METRICS_LISTEN, default :9090, off disables it. Port 8080 does not serve /metrics.
  • HTTP: uptimesebi_http_requests_total{method,route,code}, ..._request_duration_seconds (long polls and agent streams are counted but not timed), ..._requests_in_flight.
  • Checker pipeline:
    • checks_dispatched_total, check_results_total{region,ok} (own for org checkers), check_results_rejected_total{reason}, check_result_delay_seconds.
    • checker_instances{region} and checks_overdue{region} per platform region. The latter uses the new Scheduler.Overdue.
  • Notifications: notifications_total{channel_type,result}, notification_send_duration_seconds, subscriber_notifications_total, incidents_total{event}.
  • Background jobs: job_runs_total{job,result}, job_duration_seconds, job_last_success_timestamp_seconds for reconcile, housekeeping, org_purge, region_watch, domain_watch, heartbeats and alertmanager_monitors.
  • Platform totals: read on scrape, cached 15 s, new queries PlatformCounts / MonitorCounts. Covers orgs, users, monitors by type, status pages, subscribers, open incidents, pending notifications and regions online.
  • Pools: Postgres and Redis pool stats, Go runtime, process and uptimesebi_build_info.
  • Helm: api.metrics.{enabled,port} adds the container and Service port. api.metrics.serviceMonitor.enabled adds a ServiceMonitor, off by default.
  • Docs: README and .env.example.

Also: region limit in the monitor form

  • The monitor form now gets the org's regions-per-monitor limit. It shows "Up to N (platform) regions per monitor (n/N)" and locks the remaining counted regions in both the list and the map once the limit is reached.
  • Own regions stay free unless own_regions_count is set. The server check stays as it was.
  • New i18n keys monitors.regions_limit and monitors.platform_regions_limit (en/de).
  • Tests: testdata/regionlimit.html, plus a TestLimits check that the form carries the limit and that own regions are not counted.

Test plan

  • internal/metrics: HTTP middleware (routes, unmatched, streams not timed), jobs, counters, handler output, pool collectors lint-clean
  • TestMetrics (API): results, duplicates and unknown monitors counted per region; platform totals and checker gauges present
  • TestOverdueCountsRunsLeftBehind
  • helm lint, helm template with and without metrics / ServiceMonitor
  • golangci-lint clean. Full test suite green; TestDispatchSpreadsRandomly is flaky in the parallel run (shared Redis DB) and passes alone.
  • Dev stack: curl :9090/metrics shows all families with live values; :8080/metrics returns 404

After rollout: set api.metrics.serviceMonitor.enabled: true in the Flux HelmRelease. The cluster's Prometheus selects all ServiceMonitors.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

## Summary - New `internal/metrics` package (client_golang, own registry per instance) and a second listener in `cmd/api`: `UPTIME_API_METRICS_LISTEN`, default `:9090`, `off` disables it. Port 8080 does not serve `/metrics`. - **HTTP:** `uptimesebi_http_requests_total{method,route,code}`, `..._request_duration_seconds` (long polls and agent streams are counted but not timed), `..._requests_in_flight`. - **Checker pipeline:** - `checks_dispatched_total`, `check_results_total{region,ok}` (`own` for org checkers), `check_results_rejected_total{reason}`, `check_result_delay_seconds`. - `checker_instances{region}` and `checks_overdue{region}` per platform region. The latter uses the new `Scheduler.Overdue`. - **Notifications:** `notifications_total{channel_type,result}`, `notification_send_duration_seconds`, `subscriber_notifications_total`, `incidents_total{event}`. - **Background jobs:** `job_runs_total{job,result}`, `job_duration_seconds`, `job_last_success_timestamp_seconds` for reconcile, housekeeping, org_purge, region_watch, domain_watch, heartbeats and alertmanager_monitors. - **Platform totals:** read on scrape, cached 15 s, new queries `PlatformCounts` / `MonitorCounts`. Covers orgs, users, monitors by type, status pages, subscribers, open incidents, pending notifications and regions online. - **Pools:** Postgres and Redis pool stats, Go runtime, process and `uptimesebi_build_info`. - **Helm:** `api.metrics.{enabled,port}` adds the container and Service port. `api.metrics.serviceMonitor.enabled` adds a ServiceMonitor, off by default. - **Docs:** README and `.env.example`. ## Also: region limit in the monitor form - The monitor form now gets the org's regions-per-monitor limit. It shows "Up to N (platform) regions per monitor (n/N)" and locks the remaining counted regions in both the list and the map once the limit is reached. - Own regions stay free unless `own_regions_count` is set. The server check stays as it was. - New i18n keys `monitors.regions_limit` and `monitors.platform_regions_limit` (en/de). - Tests: `testdata/regionlimit.html`, plus a `TestLimits` check that the form carries the limit and that own regions are not counted. ## Test plan - [x] `internal/metrics`: HTTP middleware (routes, unmatched, streams not timed), jobs, counters, handler output, pool collectors lint-clean - [x] `TestMetrics` (API): results, duplicates and unknown monitors counted per region; platform totals and checker gauges present - [x] `TestOverdueCountsRunsLeftBehind` - [x] `helm lint`, `helm template` with and without metrics / ServiceMonitor - [x] golangci-lint clean. Full test suite green; `TestDispatchSpreadsRandomly` is flaky in the parallel run (shared Redis DB) and passes alone. - [x] Dev stack: `curl :9090/metrics` shows all families with live values; `:8080/metrics` returns 404 After rollout: set `api.metrics.serviceMonitor.enabled: true` in the Flux HelmRelease. The cluster's Prometheus selects all ServiceMonitors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 1 commit 2026-11-29 10:57:04 +00:00
feat(api): Prometheus metrics for operators
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m23s
ci / test (pull_request) Successful in 12m59s
ci / build (pull_request) Canceled after 7m17s
ci / image (pull_request) Canceled after 0s
e9984f8271
The API serves Prometheus metrics on a listener of its own
(UPTIME_API_METRICS_LISTEN, default :9090, "off" disables it), so the
public ingress never exposes them:

- requests by route and status, with durations except for long polls
  and agent streams
- dispatched checks, stored and rejected results per region, how late
  results arrive, live checkers and overdue checks per platform region
- notification and subscriber mail deliveries, incidents opened and
  resolved
- runs, duration and last success of the background jobs
- platform totals (orgs, users, monitors by type, status pages,
  subscribers, open incidents, pending notifications), read at most
  every 15 seconds when scraped
- the Postgres and Redis connection pools, Go runtime and build info

The Helm chart exposes the port on the API service and can add a
ServiceMonitor for the Prometheus Operator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi changed title from feat(api): Prometheus metrics for operators to feat(api): Prometheus metrics; fix(monitors): region limit in the form 2026-11-29 11:17:27 +00:00
Sebi added 1 commit 2026-11-29 11:17:29 +00:00
fix(monitors): stop selecting more regions than the limit allows
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m31s
ci / test (pull_request) Successful in 13m28s
ci / build (pull_request) Successful in 10m23s
ci / image (pull_request) In progress
3a7bed5a3e
The monitor form let users tick any number of regions and only the save
failed with the region limit. The form now knows the organization's
regions-per-monitor limit: it says how many regions a monitor may use,
counts the ticked ones, and once the limit is reached locks the other
regions that count towards it, in the list and on the map, until one is
unticked. Own regions stay free unless they count. The server still
enforces the limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit 6aabf9a364 into main 2026-11-29 11:21:32 +00:00
Sebi deleted branch feat/api-metrics 2026-11-29 11:21:35 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ZB-Server/uptimesebi#172