Metrics as the siblings: PromEx on :9568 with phx_vigil_* plugins

573fef1 · gmorell · 2026-12-04 03:49

42 files +1270 -118
Message
{commit_body(@commit)}

Files changed

modified ROADMAP.md
+1 −1
@@ -482,7 +482,7 @@ This is new: GlitchTip throws `check_in` items away.
482 482 - It queues a `PurgeWorker` per project or organization soft-deleted over a day ago.
483 483 - Health:
484 484 - `/_health/` (liveness) and `/api/0/internal/health/` (readiness, Sentry's shape) are served by `VigilWeb.HealthPlug`, ahead of sessions.
485 − - Prometheus `/metrics` (`telemetry_metrics_prometheus_core`) is off unless `METRICS_TOKEN` or `METRICS_PUBLIC` is set. Ingest emits `[:vigil, :ingest, :accepted | :processed]`, and backlog gauges are polled.
485 + - Prometheus: PromEx (`Vigil.PromEx`) on a second listener, port 9568 (`Vigil.MetricsPlug`), with the fleet's shared `phx_*` names and Vigil's own `phx_vigil_*` (`Vigil.PromEx.Plugins.Ingest`, `.Watch`, `.Inventory`; docs/deploy.md). The same text at `/metrics` on the site's port is off unless `METRICS_TOKEN` or `METRICS_PUBLIC` is set. Ingest emits `[:vigil, :ingest, :request | :accepted | :outcome | :processed]`; uptime checks, check-ins and alert deliveries emit their own events; buffer, monitor and inventory gauges are polled.
486 486 - Dogfooding: sentry-elixir 14.1 is a dependency, inert until `VIGIL_SELF_DSN`. It reports errors (logger handler, `PlugCapture`), Oban errors and every cron as a monitor. `Vigil.SelfReport.before_send/1` drops events whose request, Oban worker or stack frames are the ingest path. Tested end to end against the instance itself. Traces aren't reported: that needs OpenTelemetry deps.
487 487 - Packaging:
488 488 - The Dockerfile is Debian, Elixir 1.20.4 / OTP 28.5, with rustup 1.92.0 for the NIFs; the runner adds nothing for them, runs as `nobody`, and keeps storage in `/data/storage`.
modified config/config.exs
+14 −0
@@ -103,6 +103,20 @@ config :sentry,
103 103 integrations: [oban: [capture_errors: true, cron: [enabled: true]]],
104 104 before_send: {Vigil.SelfReport, :before_send}
105 105
106 +# Prometheus metrics (Vigil.PromEx), served on port 9568 by Vigil.MetricsPlug
107 +# and scraped through the pod's prometheus.io/* annotations.
108 +#
109 +# `grafana: :disabled` is load-bearing: PromEx would otherwise upload its own
110 +# dashboards on boot, and the dashboards for the fleet Vigil runs in are
111 +# committed in deployment/grafana and pushed from there. `metrics_server:
112 +# :disabled` because that option is Cowboy-based; see Vigil.MetricsPlug.
113 +config :vigil, Vigil.PromEx,
114 + disabled: false,
115 + manual_metrics_start_delay: :no_delay,
116 + drop_metrics_groups: [],
117 + grafana: :disabled,
118 + metrics_server: :disabled
119 +
106 120 # Configure the endpoint
107 121 config :vigil, VigilWeb.Endpoint,
108 122 url: [host: "localhost"],
modified config/runtime.exs
+12 −2
@@ -365,8 +365,18 @@ if bucket = System.get_env("S3_BUCKET") do
365 365 secret_access_key: System.fetch_env!("S3_SECRET_ACCESS_KEY")
366 366 end
367 367
368 −# /metrics (VigilWeb.HealthPlug): behind a bearer token, or open on a
369 −# private network, or off (the default).
368 +# The metrics listener (Vigil.MetricsPlug): 9568 unless METRICS_PORT says
369 +# otherwise; METRICS_PORT=off doesn't start it.
370 +case System.get_env("METRICS_PORT") do
371 + nil -> :ok
372 + "" -> :ok
373 + "off" -> config :vigil, :metrics_port, false
374 + port -> config :vigil, :metrics_port, String.to_integer(port)
375 +end
376 +
377 +# /metrics on the site's own port (VigilWeb.HealthPlug), the same text as
378 +# the metrics listener: behind a bearer token, or open on a private network,
379 +# or off (the default).
370 380 if token = System.get_env("METRICS_TOKEN") do
371 381 config :vigil, :metrics_token, token
372 382 end
modified config/test.exs
+17 −2
@@ -74,5 +74,20 @@ config :vigil, :uptime_opts,
74 74 req_options: [plug: {Req.Test, Vigil.Uptime.Checker}],
75 75 resolver: &Vigil.TestResolver.public/1
76 76
77 −# No periodic backlog queries against the sandboxed test database.
78 −config :vigil, :backlog_metrics, false
77 +# The pollers that ask the database: Vigil.PromEx.Plugins.* and PromEx's own
78 +# Oban queue poller. Under the Ecto sandbox those queries come from an
79 +# unowned process, so they would fail on every tick and measure nothing
80 +# worth measuring. The Vigil ones' tests call the poll functions directly.
81 +# The event metrics stay on.
82 +config :vigil, Vigil.PromEx,
83 + drop_metrics_groups: [
84 + :oban_queue_poll_metrics,
85 + :vigil_ingest_buffer_polling_events,
86 + :vigil_watch_polling_events,
87 + :vigil_inventory_polling_events,
88 + :vigil_issues_polling_events
89 + ]
90 +
91 +# An ephemeral port for the metrics listener, so `mix test` never fights a
92 +# running dev server (or a sibling app's suite) for 9568.
93 +config :vigil, :metrics_port, 0
modified docs/deploy.md
+46 −4
@@ -46,14 +46,56 @@ probes there: it answers `ok` without touching the database.
46 46 running, and the ingest buffer is under 50,000 waiting items. It answers
47 47 503, listing the problems, otherwise.
48 48
49 −`GET /metrics` is Prometheus text: request, query, ingest and Oban
50 −timings, backlog gauges and VM figures. It is off unless one of the
49 +## Metrics
50 +
51 +Prometheus metrics come from PromEx (`Vigil.PromEx`) and are served on a
52 +second listener, **port 9568**, at `/metrics`, with no token. That port is
53 +separate from the site so a proxy or Ingress that forwards everything on
54 +`PORT` doesn't publish it; keep 9568 off the internet and point the scraper
55 +at it (on Kubernetes, the `prometheus.io/scrape`, `/path` and `/port: "9568"`
56 +pod annotations).
57 +
58 +The names are PromEx's with a shared `phx_` prefix: `phx_phoenix_http_*`
59 +(requests by route pattern), `phx_beam_*`, `phx_ecto_*`, `phx_oban_*`
60 +(queue depth by state, job durations and failures) and
61 +`phx_application_*`. Vigil's own are `phx_vigil_*`:
62 +
63 +| Metric | Labels | |
64 +|---|---|---|
65 +| `phx_vigil_ingest_requests_total` | `endpoint`, `outcome` | Requests to the ingest edge: `accepted`, `rate_limited`, `not_accepting`, `denied`, `too_large`, `invalid`, `method_not_allowed` |
66 +| `phx_vigil_ingest_items_accepted_total` | `type` | Envelope items buffered |
67 +| `phx_vigil_ingest_items_dropped_total` | `source`, `category`, `reason` | Dropped at the edge, in processing, or by SDKs (client reports) |
68 +| `phx_vigil_ingest_processing_duration_milliseconds` | `type`, `result` | Histogram: one buffered item's processing |
69 +| `phx_vigil_ingest_buffer_items` | `state` | Buffered items by state (polled) |
70 +| `phx_vigil_ingest_buffer_oldest_pending_age_seconds` | | Wait of the oldest pending item (polled) |
71 +| `phx_vigil_uptime_checks_total` | `type`, `result`, `reason` | Uptime checks recorded |
72 +| `phx_vigil_uptime_check_response_time_milliseconds` | `type` | Histogram: measured response times |
73 +| `phx_vigil_uptime_monitors` | `state` | Uptime monitors up, down, pending, disabled (polled) |
74 +| `phx_vigil_monitor_check_ins_total` | `status` | Cron check-ins, missed and timed-out included |
75 +| `phx_vigil_monitors` | `health` | Cron monitors by health (polled) |
76 +| `phx_vigil_monitor_incidents_open` | | Unresolved cron incidents (polled) |
77 +| `phx_vigil_alert_deliveries_total` | `type`, `result` | Alert delivery attempts: `sent`, `retrying`, `failed` |
78 +| `phx_vigil_organizations_count`, `_projects_count`, `_users_count` | | (polled) |
79 +| `phx_vigil_issues_count` | `status` | (polled every 5 minutes) |
80 +| `phx_vigil_rows_estimate` | `table` | `pg_class.reltuples` over the partitions of `issue_events`, `spans`, `log_events`, `uptime_checks`, `monitor_checkins` (polled) |
81 +
82 +Counters and histograms are per replica: sum them. The polled gauges ask
83 +the database, so every replica reports the same number: aggregate them with
84 +`max`, never `sum`.
85 +
86 +The same text is also available at `GET /metrics` on the site's own port,
87 +for a scraper that can only reach that, but it is off unless one of the
51 88 variables below turns it on.
52 89
53 90 | Variable | Default | |
54 91 |---|---|---|
55 −| `METRICS_TOKEN` | unset | Serves `/metrics` to `Authorization: Bearer <token>` |
56 −| `METRICS_PUBLIC` | `false` | `true` serves `/metrics` to anyone (scrape over a private network only) |
92 +| `METRICS_PORT` | `9568` | The metrics listener's port; `off` doesn't start it |
93 +| `METRICS_TOKEN` | unset | Serves `/metrics` on `PORT` to `Authorization: Bearer <token>` |
94 +| `METRICS_PUBLIC` | `false` | `true` serves `/metrics` on `PORT` to anyone (scrape over a private network only) |
95 +
96 +Before PromEx, `/metrics` on `PORT` served `vigil_*` names from
97 +`telemetry_metrics_prometheus_core`; those names are gone, replaced by the
98 +ones above.
57 99
58 100 ## Environment
59 101
modified lib/vigil/alerts/deliver_worker.ex
+12 −0

Click to load diff…

modified lib/vigil/application.ex
+9 −0

Click to load diff…

modified lib/vigil/ingest/outcomes.ex
+7 −0

Click to load diff…

added lib/vigil/metrics_plug.ex
+39 −0

Click to load diff…

modified lib/vigil/monitors.ex
+11 −0

Click to load diff…

added lib/vigil/prom_ex.ex
+63 −0

Click to load diff…

added lib/vigil/prom_ex/plugins/ingest.ex
+186 −0

Click to load diff…

added lib/vigil/prom_ex/plugins/inventory.ex
+172 −0

Click to load diff…

added lib/vigil/prom_ex/plugins/watch.ex
+167 −0

Click to load diff…

modified lib/vigil/uptime.ex
+11 −0

Click to load diff…

modified lib/vigil_web/health_plug.ex
+14 −6

Click to load diff…

modified lib/vigil_web/ingest_plug.ex
+44 −13

Click to load diff…

modified lib/vigil_web/telemetry.ex
+6 −86

Click to load diff…

modified mix.exs
+6 −2

Click to load diff…

modified mix.lock
+5 −0

Click to load diff…

added test/support/telemetry_helpers.ex
+45 −0

Click to load diff…

modified test/vigil/alerts_test.exs
+7 −0

Click to load diff…

added test/vigil/metrics_plug_test.exs
+50 −0

Click to load diff…

added test/vigil/prom_ex/plugins/ingest_test.exs
+134 −0

Click to load diff…

added test/vigil/prom_ex/plugins/inventory_test.exs
+57 −0

Click to load diff…

added test/vigil/prom_ex/plugins/watch_test.exs
+132 −0

Click to load diff…

modified test/vigil_web/health_plug_test.exs
+3 −2

Click to load diff…

Parents: bbb2a48