themis/histogram

Functions

pub fn init_record(
  store store: Store,
  histogram_name name_string: String,
  labels labels_dict: Dict(String, String),
) -> Result(Store, StoreError)

Initializes a new histogram metric record with the given labels.

Arguments

  • store: The metrics store containing the histogram
  • histogram_name: The name of the histogram
  • labels: A dictionary of labels
  • bucket_boundaries: A set of numbers defining the buckets by their le limits

Note that a +Inf bucket is always added by default if it isn’t provided.

Examples

let labels = dict.from_list([#("instance", "localhost:9090")])
let buckets = set.from_list(
  [
    number.decimal(0.05), 
    number.decimal(0.1), 
    number.decimal(0.2), 
    number.decimal(0.5),
    number.integer(1),
  ]
)
let assert Ok(store) = init_record(
  store,
  "app_request_processing_seconds",
  labels,
  buckets,
)
pub fn observe(
  store store: Store,
  histogram_name name_string: String,
  labels labels_dict: Dict(String, String),
  value value: Number,
) -> Result(Store, StoreError)

Records an observation value for a histogram metric.

Arguments

  • store: The metrics store containing the histogram
  • histogram_name: The name of the histogram metric
  • labels: A dictionary of labels
  • value: The value to record in the histogram

Examples

let labels = dict.from_list([#("instance", "localhost:9090")])
let value = number.decimal(0.123)
let assert Ok(store) = observe(
  store,
  "app_request_processing_seconds", 
  labels,
  value,
)
pub fn register(
  store store: Store,
  name name_string: String,
  description description: String,
  buckets buckets: Set(Number),
) -> Result(Store, StoreError)

Registers a new histogram metric to the store.

Arguments

  • store: The metrics store to add the histogram to
  • name: The name of the new histogram metric (must be a valid Prometheus metric name)
  • description: A human-readable description of what the histogram observes
  • buckets: A set of numbers defining the buckets by their le limits

Examples

let assert Ok(store) = register(
  store,
  "app_request_processing_seconds",
  "Time spent processing request",
)
pub fn unregister(
  store store: Store,
  histogram_name name_string: String,
) -> Result(Store, StoreError)

Unregisters a new histogram metric to the store.

Arguments

  • store: The metrics store to add the histogram to
  • name: The name of the new histogram metric (must be a valid Prometheus metric name)

Examples

let assert Ok(store) = unregister(
  store,
  "app_request_processing_seconds",
)
Search Document