pharos/metric

The canonical metric record.

Measurement (BEAM/host) and MetricSample (custom probes) are the typed shapes the collection and threshold lanes work with. Metric is the flat, transport-ready shape the resilient pipeline buffers and ships: a single named scalar with labels and a capture timestamp. One typed measurement fans out into several Metrics (one per numeric field).

Keeping Metric deliberately flat (name + value + labels + timestamp) means the hot buffer, spillover store, and sinks never need to know about the BEAM/host/probe taxonomy: they move opaque scalars.

Types

A single named numeric reading at a point in time.

  • name - dotted metric name, e.g. "vm.memory.total".
  • value - the reading, always a float (ints are widened on capture).
  • labels - dimensions for the reading, e.g. #("host", "node1").
  • timestamp_ms - erlang:system_time(millisecond) at capture.
pub type Metric {
  Metric(
    name: String,
    value: Float,
    labels: dict.Dict(String, String),
    timestamp_ms: Int,
  )
}

Constructors

  • Metric(
      name: String,
      value: Float,
      labels: dict.Dict(String, String),
      timestamp_ms: Int,
    )

Values

pub fn from_measurement(
  measurement: measurement.Measurement,
) -> List(Metric)

Flatten a decoded Measurement into its constituent Metrics (one per numeric field), all sharing a single capture timestamp. Non-numeric measurements (ProcessInfo) and host probes still reporting Unimplemented yield no metrics.

pub fn from_sample(
  probe_id: String,
  sample: dict.Dict(String, Float),
) -> List(Metric)

Flatten a custom probe sample (field -> value) into Metrics named probe.<probe_id>.<field>.

pub fn labelled(
  name name: String,
  value value: Float,
  labels labels: dict.Dict(String, String),
) -> Metric

Build a metric with labels, stamped with the current wall-clock time.

pub fn new(name name: String, value value: Float) -> Metric

Build a metric with no labels, stamped with the current wall-clock time.

pub fn with_label(
  metric: Metric,
  key: String,
  value: String,
) -> Metric

Attach (or overwrite) a single label on a metric.

Search Document