themis

Types

A Store manages a collection of metrics, ensuring unique metric names.

pub opaque type Store

Represents possible errors that can occur when operating on the Store.

pub type StoreError {
  MetricNameAlreadyInUse
  MetricNameNotFound
  MetricError(metric.MetricError)
  LabelError(label.LabelError)
}

Constructors

  • MetricNameAlreadyInUse

    Returned when attempting to create a metric with a name that’s already in use

  • MetricNameNotFound

    Returned when attempting to operate on a metric that doesn’t exist

  • MetricError(metric.MetricError)

    Wraps errors related to metric name validation

  • LabelError(label.LabelError)

    Wraps errors related to label validation

Functions

pub fn add_gauge(
  store store: Store,
  name name_string: String,
  description description: String,
) -> Result(Store, StoreError)

Adds a new gauge metric to the store.

Arguments

  • store: The metrics store to add the gauge to
  • name: The name of the gauge metric (must be a valid Prometheus metric name)
  • description: A human-readable description of what the gauge measures

Examples

let assert Ok(store) = add_gauge(
  store,
  "process_cpu_seconds_total",
  "Total user and system CPU time spent in seconds",
)
pub fn dec(value value: Float) -> Number

Creates a Number representing a decimal value.

pub fn delete_gauge(
  store store: Store,
  gauge_name name_string: String,
) -> Result(Store, StoreError)

Removes a gauge metric and all its recorded values from the store.

Arguments

  • store: The metrics store containing the gauge
  • gauge_name: The name of the gauge to delete

Examples

let assert Ok(store) = delete_gauge(store, "process_cpu_seconds_total")
pub fn insert_gauge_record(
  store store: Store,
  gauge_name name_string: String,
  labels labels_dict: Dict(String, String),
  value value: Number,
) -> Result(Store, StoreError)

Records a value for a gauge metric with the given labels.

Arguments

  • store: The metrics store containing the gauge
  • gauge_name: The name of the gauge to record a value for
  • labels: A dictionary of labels
  • value: The numeric value to record

Examples

let labels = dict.from_list([#("instance", "localhost:9090")])
let assert Ok(store) = insert_gauge_record(
  store,
  "process_cpu_seconds_total",
  labels,
  int(42),
)
pub fn int(value value: Int) -> Number

Creates a Number representing an integer value.

pub fn nan() -> Number

Creates a Number representing NaN (Not a Number).

pub fn neg_inf() -> Number

Creates a Number representing negative infinity.

pub fn new() -> Store

Creates a new empty metrics store.

pub fn pos_inf() -> Number

Creates a Number representing positive infinity.

pub fn print(metrics_store store: Store) -> String

Formats all metrics in the store as a Prometheus-compatible text string.

Examples

let metrics_text = print(store)
// HELP my_gauge My first gauge
// TYPE my_gauge gauge
// my_gauge{foo="bar"} 10
// my_gauge{toto="tata",wibble="wobble"} +Inf
Search Document