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

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
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-29 11:56:46 +01:00
1 parent ab25c1f218
commit e9984f8271
30 files changed
+1005 -20

No files matched your search

+15 -1
View File
@@ -298,6 +298,7 @@ func (s *Server) agentResults(c *gin.Context) {
internalError(c, err)
return
}
s.metrics.Rejected("duplicate", len(req.Results)-len(fresh))
req.Results = fresh
ids := make([]uuid.UUID, len(req.Results))
for i, r := range req.Results {
@@ -308,6 +309,8 @@ func (s *Server) agentResults(c *gin.Context) {
var (
accepted []agentapi.Result
changed []uuid.UUID
unknown int
badTime int
)
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
a := agentOf(c)
@@ -325,7 +328,12 @@ func (s *Server) agentResults(c *gin.Context) {
// A checker may only report monitors of its own region, and
// timestamps far from now are rejected rather than skewing
// history.
if !ok || r.StartedAt.After(now.Add(time.Minute)) || r.StartedAt.Before(now.Add(-24*time.Hour)) {
switch {
case !ok:
unknown++
continue
case r.StartedAt.After(now.Add(time.Minute)) || r.StartedAt.Before(now.Add(-24*time.Hour)):
badTime++
continue
}
row := store.InsertCheckResultsParams{
@@ -353,6 +361,12 @@ func (s *Server) agentResults(c *gin.Context) {
internalError(c, err)
return
}
s.metrics.Rejected("unknown_monitor", unknown)
s.metrics.Rejected("bad_time", badTime)
label := regionLabel(agentOf(c))
for _, r := range accepted {
s.metrics.Result(label, r.OK, now.Sub(r.StartedAt))
}
s.pagesChanged(ctx, changed...)
s.evaluateResults(ctx, region, accepted, monitors)
s.storeEvidence(ctx, region, instance, accepted, monitors)