promgleam/metrics/histogram
A histogram samples observations (usually things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.
Functions
pub fn create_histogram(
registry registry: String,
name name: String,
help help: String,
labels labels: List(String),
buckets buckets: List(Float),
) -> Result(Nil, String)
Creates a new Histogram metric.
Examples
create_histogram(
registry: "default",
name: "http_request_duration_seconds",
help: "Duration of HTTP requests in seconds",
labels: [ "method", "route", "status" ],
buckets: [ 0.1, 0.25, 0.5, 1.0, 1.5 ],
)
pub fn measure_histogram(
registry registry: String,
name name: String,
labels labels: List(String),
func func: fn() -> a,
) -> Result(a, String)
Measures a function execution time in milliseconds and observes that in the Histogram.
Examples
fn my_function_to_measure() {
use <- measure_histogram(
registry: "default",
name: "function_execution_time",
labels: [ "my_function_to_measure" ],
)
// Do something slow here
"return_value"
}
let assert Ok("return_value") = my_function_to_measure()
fn my_function_to_measure() {
// Do something slow here
"return_value"
}
let assert Ok("return_value") =
my_function_to_measure
|> measure_histogram(
registry: "default",
name: "function_execution_time",
labels: [ "my_function_to_measure" ],
func: _
)
pub fn measure_histogram_seconds(
registry registry: String,
name name: String,
labels labels: List(String),
func func: fn() -> a,
) -> Result(a, String)
Measures a function execution time in seconds and observes that in the Histogram.
Examples
fn my_function_to_measure() {
use <- measure_histogram_seconds(
registry: "default",
name: "function_execution_time",
labels: [ "my_function_to_measure" ],
)
// Do something slow here
"return_value"
}
let assert Ok("return_value") = my_function_to_measure()
fn my_function_to_measure() {
// Do something slow here
"return_value"
}
let assert Ok("return_value") =
my_function_to_measure
|> measure_histogram_seconds(
registry: "default",
name: "function_execution_time",
labels: [ "my_function_to_measure" ],
func: _
)
pub fn observe_histogram(
registry registry: String,
name name: String,
labels labels: List(String),
value value: Float,
) -> Result(Nil, String)
Observes a value in the Histogram.
Examples
observe_histogram(
registry: "default",
name: "http_request_duration_seconds",
labels: [ "GET", "/", "200" ],
value: 0.23,
)