Botica.Report (Botica v2.2.0)

Copy Markdown View Source

Exports check results to observability backends.

Two exporters are provided:

  • prometheus_text/1 — renders results in the Prometheus text exposition format (application/openmetrics-compatible subset), ready for a Prometheus / VictoriaMetrics scrape endpoint.
  • otel_export/1 — emits OTel-style metrics via :telemetry events, so any OTel collector handler attached to [:botica, :report, :otel] receives them.

Examples

results = [
  %{id: :database, name: "Database", status: :ok, message: "up", fix_command: nil},
  %{id: :memory, name: "Memory", status: :warning, message: "low", fix_command: nil}
]

iex> Botica.Report.prometheus_text(results)
"# HELP botica_check_status ..."

iex> Botica.Report.otel_export(results)
:ok

Summary

Functions

Overall health status from a summary: :ok | :degraded | :fail.

Emits OTel-style metrics for every result via :telemetry.

Renders results in Prometheus text exposition format.

Aggregates results into a summary (delegates to Botica.Check.Result).

Functions

health_status(summary)

@spec health_status(map()) :: :ok | :degraded | :fail

Overall health status from a summary: :ok | :degraded | :fail.

otel_export(results)

@spec otel_export([Botica.Check.Result.t() | map()]) :: :ok

Emits OTel-style metrics for every result via :telemetry.

Each check emits:

:telemetry.execute(
  [:botica, :report, :otel],
  %{value: 1},
  %{check: id, status: "ok", name: name}
)

Attach a handler on that event in your OTel exporter to forward the metrics. Returns :ok unconditionally (telemetry never blocks).

prometheus_text(results)

@spec prometheus_text([Botica.Check.Result.t() | map()]) :: binary()

Renders results in Prometheus text exposition format.

Each check produces a gauge line:

# HELP botica_check_status Current status of botica health checks
# TYPE botica_check_status gauge
botica_check_status{check="database",status="ok"} 1

The check id and status are emitted as labels; the value is always 1 (the status is encoded in the label). Label values are escaped per the Prometheus spec (backslash, double-quote, newline).

summary(results)

@spec summary([Botica.Check.Result.t() | map()]) :: map()

Aggregates results into a summary (delegates to Botica.Check.Result).