PhoenixKitStats.Metrics (PhoenixKitStats v0.2.1)

Copy Markdown View Source

Thin wrapper around Barograph for querying and charting a stats group's time-series data.

Group metadata CRUD (name, key, port, status) lives in PhoenixKitStats.Groups; this module only reads/renders metric data from a group's already-open Barograph database (see PhoenixKitStats.DatabaseManager).

Summary

Functions

Runs query/3 and renders the result as a Barograph SVG line chart.

Lists distinct metric names recorded in a group's database.

Lists series (metric + labels) for a group, optionally filtered to one metric.

Runs a bucketed/raw time-series query for one metric. See Barograph.query/3 for opts.

Functions

chart_svg(group, metric, opts \\ [])

@spec chart_svg(PhoenixKitStats.Schemas.Group.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Runs query/3 and renders the result as a Barograph SVG line chart.

opts accepts both query options (:labels, :from, :to, :bucket, :agg) and chart options (:width, :height, :style) — the chart-only keys are split out before querying.

list_metric_names(group)

@spec list_metric_names(PhoenixKitStats.Schemas.Group.t()) ::
  {:ok, [String.t()]} | {:error, term()}

Lists distinct metric names recorded in a group's database.

No dedicated Barograph API exists for this — it's the intended use of Barograph's "raw SQL, never second-class" guarantee against its internal bg_series table.

list_series(group, metric \\ nil)

@spec list_series(PhoenixKitStats.Schemas.Group.t(), String.t() | nil) ::
  {:ok, [map()]} | {:error, term()}

Lists series (metric + labels) for a group, optionally filtered to one metric.

query(group, metric, opts \\ [])

@spec query(PhoenixKitStats.Schemas.Group.t(), String.t(), keyword()) ::
  {:ok, [map()]} | {:error, term()}

Runs a bucketed/raw time-series query for one metric. See Barograph.query/3 for opts.