Caddy.Metrics.Poller (Caddy v2.3.1)

View Source

Periodic metrics collection from Caddy's Prometheus endpoint.

This GenServer periodically fetches metrics from Caddy and emits telemetry events with the collected data.

Configuration

config :caddy,
  metrics_enabled: true,
  metrics_interval: 15_000  # milliseconds

Starting the Poller

# Manual start
Caddy.Metrics.Poller.start_link(interval: 15_000)

# Check if running
Caddy.Metrics.Poller.running?()

# Stop the poller
Caddy.Metrics.Poller.stop()

Telemetry Events

When metrics are collected, the following event is emitted:

[:caddy, :metrics, :collected]

With measurements containing all parsed metric values.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get the current interval setting.

Get the last collected metrics.

Trigger an immediate metrics collection.

Check if the poller is running.

Start the metrics poller.

Stop the metrics poller.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

interval(server \\ __MODULE__)

@spec interval(GenServer.server()) :: pos_integer()

Get the current interval setting.

last_metrics(server \\ __MODULE__)

@spec last_metrics(GenServer.server()) :: Caddy.Metrics.t() | nil

Get the last collected metrics.

poll_now(server \\ __MODULE__)

@spec poll_now(GenServer.server()) :: :ok

Trigger an immediate metrics collection.

running?(server \\ __MODULE__)

@spec running?(GenServer.server()) :: boolean()

Check if the poller is running.

set_interval(new_interval, server \\ __MODULE__)

@spec set_interval(pos_integer(), GenServer.server()) :: :ok

Update the polling interval.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the metrics poller.

Options

  • :interval - Polling interval in milliseconds (default: 15000)
  • :name - Process name (default: Caddy.Metrics.Poller)

stop(server \\ __MODULE__)

@spec stop(GenServer.server()) :: :ok

Stop the metrics poller.