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 toname
: 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 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 gaugegauge_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 gaugegauge_name
: The name of the gauge to record a value forlabels
: A dictionary of labelsvalue
: 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 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