prop/lib/microwaveprop/prom_ex.ex
Graham McIntire c7bc3ed5d0
feat(telemetry): PromEx Prometheus exporter at /metrics
Wires PromEx with its built-in Application / BEAM / Phoenix / Ecto /
Oban plugins plus a custom `Microwaveprop.PromEx.InstrumentPlugin`
that registers Prometheus histograms for every
`Microwaveprop.Instrument` span (HRRR/NEXRAD/IEM/GEFS/NARR/UWYO
/Elevation fetches, DB batch upserts, terrain analysis, radar
aggregation, propagation score band). Queue-depth gauges from the
10-second poller land at `microwaveprop_oban_queue_count{queue,state}`.

Router forwards `/metrics` to MicrowavepropWeb.MetricsPlug which
optionally requires a bearer token (`PROMETHEUS_AUTH_TOKEN` env var in
runtime.exs); leave it unset to expose metrics publicly and restrict
at the ingress / Cloudflare Access layer instead.

Example external Prometheus scrape config:

    scrape_configs:
      - job_name: microwaveprop
        scrape_interval: 30s
        metrics_path: /metrics
        scheme: https
        authorization:
          type: Bearer
          credentials: <token>
        static_configs:
          - targets: ['prop.w5isp.com:443']
2026-04-18 16:39:39 -05:00

47 lines
1.4 KiB
Elixir

defmodule Microwaveprop.PromEx do
@moduledoc """
Prometheus metrics exporter. Combines PromEx's built-in plugins for
Application/BEAM/Phoenix/Ecto/Oban with our own custom metrics
(Microwaveprop.Instrument spans, Oban queue-depth gauges).
A dedicated Prometheus server outside the Kubernetes cluster scrapes
`/metrics` over the app's normal HTTP endpoint. The `MicrowavepropWeb.Router`
is responsible for making that route reachable.
"""
use PromEx, otp_app: :microwaveprop
alias PromEx.Plugins
@impl true
def plugins do
[
# Defaults: VM memory, process counts, scheduler util, app version.
Plugins.Application,
Plugins.Beam,
# Phoenix: request duration by route/status, channel/socket events.
{Plugins.Phoenix, router: MicrowavepropWeb.Router, endpoint: MicrowavepropWeb.Endpoint},
# Ecto: query duration, queue time, pool size.
{Plugins.Ecto, otp_app: :microwaveprop, repos: [Microwaveprop.Repo]},
# Oban: job duration, queue time, state counts, queue depth.
Plugins.Oban,
# Our own spans: Instrument.span/3 emits [:microwaveprop | suffix]
# events; this plugin converts them to Prometheus histograms.
Microwaveprop.PromEx.InstrumentPlugin
]
end
@impl true
def dashboards do
[
{:prom_ex, "application.json"},
{:prom_ex, "beam.json"},
{:prom_ex, "phoenix.json"},
{:prom_ex, "ecto.json"},
{:prom_ex, "oban.json"}
]
end
end