1 defmodule Pleroma.PrometheusExporter do
3 Exports metrics in Prometheus format.
4 Mostly exists because of https://github.com/beam-telemetry/telemetry_metrics_prometheus_core/issues/52
5 Basically we need to fetch metrics every so often, or the lib will let them pile up and eventually crash the VM.
6 It also sorta acts as a cache so there is that too.
12 def start_link(_opts) do
13 GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
22 Process.send_after(self(), :gather, 60_000)
25 # Scheduled function, gather metrics and schedule next run
26 def handle_info(:gather, _state) do
28 state = TelemetryMetricsPrometheus.Core.scrape()
32 # Trigger the call dynamically, mostly for testing
33 def handle_call(:gather, _from, _state) do
34 state = TelemetryMetricsPrometheus.Core.scrape()
35 {:reply, state, state}
38 def handle_call(:show, _from, state) do
39 {:reply, state, state}
43 GenServer.call(__MODULE__, :show)
47 GenServer.call(__MODULE__, :gather)