### linear function example Source: https://hexdocs.pm/promgleam/promgleam/buckets.html Example usage of the linear function to create 4 buckets starting at 1.0 with a step of 3.0. ```gleam let assert Ok([1.0, 4.0, 7.0, 10.0]) = linear(start: 1.0, step: 3.0, count: 4) ``` -------------------------------- ### exponential function example Source: https://hexdocs.pm/promgleam/promgleam/buckets.html Example usage of the exponential function to create 4 buckets starting at 1.0 with a factor of 2. ```gleam let assert Ok([1.0, 2.0, 4.0, 8.0]) = exponential(start: 1.0, factor: 2, count: 4) ``` -------------------------------- ### create_gauge example Source: https://hexdocs.pm/promgleam/promgleam/metrics/gauge.html Example of creating a gauge metric named 'cache_size' with a help text and a label 'cache_name'. ```gleam create_gauge( registry: "default", name: "cache_size", help: "Number of items in the cache", labels: [ "cache_name" ], ) ``` -------------------------------- ### Install PromGleam Source: https://hexdocs.pm/promgleam/index.html Add the library to your Gleam project using the gleam CLI. ```bash gleam add promgleam ``` -------------------------------- ### measure_histogram usage examples Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Examples showing how to measure function execution time using the use keyword or pipe operator. ```gleam 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() ``` ```gleam 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: _ ) ``` -------------------------------- ### create_histogram usage example Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Example of creating a histogram for HTTP request durations. ```gleam 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 ], ) ``` -------------------------------- ### create_counter example Source: https://hexdocs.pm/promgleam/promgleam/metrics/counter.html Example usage of create_counter to create a counter named 'http_requests_total' with labels for method, route, and status. ```gleam create_counter( registry: "default", name: "http_requests_total", help: "Total number of HTTP requests", labels: [ "method", "route", "status" ], ) ``` -------------------------------- ### set_gauge example Source: https://hexdocs.pm/promgleam/promgleam/metrics/gauge.html Example of setting the gauge 'cache_size' to 123 with label 'image_cache'. ```gleam set_gauge( registry: "default", name: "cache_size", labels: [ "image_cache" ], value: 123, ) ``` -------------------------------- ### increment_counter example Source: https://hexdocs.pm/promgleam/promgleam/metrics/counter.html Example usage of increment_counter to increment the 'http_requests_total' counter by 1 with label values for GET, /, and 200. ```gleam increment_counter( registry: "default", name: "http_requests_total", labels: [ "GET", "/", "200" ], value: 1, ) ``` -------------------------------- ### measure_histogram_seconds usage examples Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Examples showing how to measure function execution time in seconds using the use keyword or pipe operator. ```gleam 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() ``` ```gleam 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: _ ) ``` -------------------------------- ### observe_histogram usage example Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Example of observing a value in a histogram. ```gleam observe_histogram( registry: "default", name: "http_request_duration_seconds", labels: [ "GET", "/", "200" ], value: 0.23, ) ``` -------------------------------- ### linear Source: https://hexdocs.pm/promgleam/promgleam/buckets.html Creates count buckets, each step wide, where the lowest bucket has an upper bound of start. ```APIDOC ## linear ### Description Creates `count` buckets, each `step` wide, where the lowest bucket has an upper bound of `start`. ### Function Signature ```gleam pub fn linear( start start: Float, step step: Float, count count: Int, ) -> Result(List(Float), String) ``` ### Parameters - **start** (Float) - Required - The upper bound of the lowest bucket. - **step** (Float) - Required - The width of each bucket. - **count** (Int) - Required - The number of buckets to create. ### Returns - **Result(List(Float), String)** - A list of bucket upper bounds, or an error string. ### Example ```gleam let assert Ok([1.0, 4.0, 7.0, 10.0]) = linear(start: 1.0, step: 3.0, count: 4) ``` ``` -------------------------------- ### measure function usage Source: https://hexdocs.pm/promgleam/promgleam/utils.html Example showing how to use the measure function to capture the execution time of a custom function. ```gleam fn my_func() { "wibble" } let assert #(time_taken, "wibble") = measure(my_func) ``` -------------------------------- ### exponential Source: https://hexdocs.pm/promgleam/promgleam/buckets.html Creates count buckets, where the lowest bucket has an upper bound of start and each following bucket's upper bound is factor times the previous bucket's upper bound. ```APIDOC ## exponential ### Description Creates `count` buckets, where the lowest bucket has an upper bound of `start` and each following bucket's upper bound is `factor` times the previous bucket's upper bound. ### Function Signature ```gleam pub fn exponential( start start: Float, factor factor: Int, count count: Int, ) -> Result(List(Float), String) ``` ### Parameters - **start** (Float) - Required - The upper bound of the lowest bucket. - **factor** (Int) - Required - The multiplier for each subsequent bucket's upper bound. - **count** (Int) - Required - The number of buckets to create. ### Returns - **Result(List(Float), String)** - A list of bucket upper bounds, or an error string. ### Example ```gleam let assert Ok([1.0, 2.0, 4.0, 8.0]) = exponential(start: 1.0, factor: 2, count: 4) ``` ``` -------------------------------- ### print_as_protobuf function signature Source: https://hexdocs.pm/promgleam/promgleam/registry.html Serialises the registry using the Prometheus Protobuf format. The function takes the registry name as a String and returns a BitArray. ```gleam pub fn print_as_protobuf( registry_name registry_name: String, ) -> BitArray ``` -------------------------------- ### print_as_protobuf Source: https://hexdocs.pm/promgleam/promgleam/registry.html Serialises the registry using the Prometheus Protobuf format. ```APIDOC ## print_as_protobuf ### Description Serialises the registry using the Prometheus Protobuf format. ### Function Signature pub fn print_as_protobuf(registry_name: String) -> BitArray ### Parameters - **registry_name** (String) - The name of the registry to serialize. ### Return Value BitArray - The serialized registry in Prometheus Protobuf format. ``` -------------------------------- ### print_as_text function signature Source: https://hexdocs.pm/promgleam/promgleam/registry.html Serialises the registry using the Prometheus text-based format. The function takes the registry name as a String and returns a String. ```gleam pub fn print_as_text( registry_name registry_name: String, ) -> String ``` -------------------------------- ### Create and observe a Histogram Source: https://hexdocs.pm/promgleam/index.html Histograms sample observations like durations or sizes into configurable buckets. ```gleam import promgleam/metrics/histogram.{create_histogram, observe_histogram} 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 ], ) observe_histogram( registry: "default", name: "http_request_duration_seconds", labels: [ "GET", "/", "200" ], value: 0.23, ) ``` -------------------------------- ### print_as_text Source: https://hexdocs.pm/promgleam/promgleam/registry.html Serialises the registry using the Prometheus text-based format. ```APIDOC ## print_as_text ### Description Serialises the registry using the Prometheus text-based format. ### Function Signature pub fn print_as_text(registry_name: String) -> String ### Parameters - **registry_name** (String) - The name of the registry to serialize. ### Return Value String - The serialized registry in Prometheus text-based format. ``` -------------------------------- ### Print metric registry contents Source: https://hexdocs.pm/promgleam/index.html Serialize the registry using either text-based format or Protobuf format. ```gleam import promgleam/registry.{print_as_text, print_as_protobuf} print_as_text(registry_name: "default") print_as_protobuf(registry_name: "default") ``` -------------------------------- ### create_counter Source: https://hexdocs.pm/promgleam/promgleam/metrics/counter.html Creates a new Counter metric with the given registry, name, help text, and labels. Returns a Result indicating success or an error string. ```APIDOC ## create_counter ### Description Creates a new Counter metric. ### Function Signature pub fn create_counter( registry registry: String, name name: String, help help: String, labels labels: List(String), ) -> Result(Nil, String) ### Parameters - **registry** (String) - Required - The registry to create the counter in. - **name** (String) - Required - The name of the counter metric. - **help** (String) - Required - Help text describing the counter. - **labels** (List(String)) - Required - List of label names for the counter. ### Return Value Result(Nil, String) - Ok(Nil) on success, or Error(String) on failure. ### Example ```gleam create_counter( registry: "default", name: "http_requests_total", help: "Total number of HTTP requests", labels: [ "method", "route", "status" ], ) ``` ``` -------------------------------- ### create_gauge Source: https://hexdocs.pm/promgleam/promgleam/metrics/gauge.html Creates a new Gauge metric. ```APIDOC ## create_gauge ### Description Creates a new Gauge metric. ### Function Signature pub fn create_gauge(registry: String, name: String, help: String, labels: List(String)) -> Result(Nil, String) ### Parameters - **registry** (String) - Required - The registry to create the gauge in. - **name** (String) - Required - The name of the gauge metric. - **help** (String) - Required - Help text describing the metric. - **labels** (List(String)) - Required - List of label names for the metric. ### Return Value Result(Nil, String) - Returns Ok(Nil) on success, or an error string on failure. ### Example ```gleam create_gauge( registry: "default", name: "cache_size", help: "Number of items in the cache", labels: [ "cache_name" ], ) ``` ``` -------------------------------- ### create_counter function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/counter.html Defines the create_counter function that creates a new Counter metric. It takes a registry name, metric name, help text, and a list of label names, returning a Result. ```gleam pub fn create_counter( registry registry: String, name name: String, help help: String, labels labels: List(String), ) -> Result(Nil, String) ``` -------------------------------- ### Create and set a Gauge Source: https://hexdocs.pm/promgleam/index.html Gauges represent numerical values that can fluctuate, such as memory usage or concurrent request counts. ```gleam import promgleam/metrics/gauge.{create_gauge, set_gauge} create_gauge( registry: "default", name: "cache_size", help: "Number of items in the cache", labels: [ "cache_name" ], ) set_gauge( registry: "default", name: "cache_size", labels: [ "image_cache" ], value: 123, ) ``` -------------------------------- ### Generate Histogram buckets Source: https://hexdocs.pm/promgleam/index.html Utility functions for creating exponential or linear buckets for Histograms. ```gleam import promgleam/buckets.{exponential, linear} exponential(start: 1.0, factor: 2, count: 5) // Ok([1.0, 2.0, 4.0, 8.0, 10.0]) linear(start: 1.0, step: 3.0, count: 4) // Ok([1.0, 4.0, 7.0, 10.0]) ``` -------------------------------- ### create_histogram Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Creates a new Histogram metric with the given registry, name, help, labels, and buckets. ```APIDOC ## create_histogram ### Description Creates a new Histogram metric. ### Function Signature ```gleam pub fn create_histogram( registry registry: String, name name: String, help help: String, labels labels: List(String), buckets buckets: List(Float), ) -> Result(Nil, String) ``` ### Parameters - `registry` (String) - Required - The registry to create the histogram in. - `name` (String) - Required - The name of the histogram metric. - `help` (String) - Required - Help text describing the histogram. - `labels` (List(String)) - Required - List of label names for the histogram. - `buckets` (List(Float)) - Required - List of bucket boundaries for the histogram. ### Returns - `Result(Nil, String)` - Ok(Nil) on success, or Error(String) on failure. ### Example ```gleam 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 ], ) ``` ``` -------------------------------- ### Measure function execution time with Histogram Source: https://hexdocs.pm/promgleam/index.html Use measure_histogram to automatically wrap a function and record its execution time. ```gleam import promgleam/metrics/histogram.{measure_histogram} fn my_function_to_measure() { use <- measure_histogram( registry: "default", name: "function_execution_time", labels: [ "my_function_to_measure" ], ) // Do something slow here } ``` -------------------------------- ### create_gauge function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/gauge.html Function signature for creating a new gauge metric. Takes registry, name, help, and labels, and returns a Result. ```gleam pub fn create_gauge( registry registry: String, name name: String, help help: String, labels labels: List(String), ) -> Result(Nil, String) ``` -------------------------------- ### Create and increment a Counter Source: https://hexdocs.pm/promgleam/index.html Counters are cumulative metrics that only increase or reset to zero. Use them for tracking requests, tasks, or errors. ```gleam import promgleam/metrics/counter.{create_counter, increment_counter} create_counter( registry: "default", name: "http_requests_total", help: "Total number of HTTP requests", labels: [ "method", "route", "status" ], ) increment_counter( registry: "default", name: "http_requests_total", labels: [ "GET", "/", "200" ], value: 1, ) ``` -------------------------------- ### create_histogram function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html The signature for creating a new Histogram metric. ```gleam pub fn create_histogram( registry registry: String, name name: String, help help: String, labels labels: List(String), buckets buckets: List(Float), ) -> Result(Nil, String) ``` -------------------------------- ### measure_histogram_seconds function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html The signature for measuring function execution time in seconds. ```gleam pub fn measure_histogram_seconds( registry registry: String, name name: String, labels labels: List(String), func func: fn() -> a, ) -> Result(a, String) ``` -------------------------------- ### measure Source: https://hexdocs.pm/promgleam/promgleam/utils.html Measures the execution time of a function in milliseconds and returns the time along with the function's return value. ```APIDOC ## measure ### Description Measures the execution time of a function in milliseconds, then returns that with the function return value in a tuple. ### Signature pub fn measure(func: fn() -> a) -> #(Int, a) ### Parameters - **func** (fn() -> a) - Required - The function to measure. ### Returns - **#(Int, a)** - A tuple containing the execution time in milliseconds and the function's return value. ### Example ```gleam fn my_func() { "wibble" } let assert #(time_taken, "wibble") = measure(my_func) ``` ``` -------------------------------- ### exponential function definition Source: https://hexdocs.pm/promgleam/promgleam/buckets.html Defines the exponential function signature for generating histogram buckets. ```gleam pub fn exponential( start start: Float, factor factor: Int, count count: Int, ) -> Result(List(Float), String) ``` -------------------------------- ### measure_histogram function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html The signature for measuring function execution time in milliseconds. ```gleam pub fn measure_histogram( registry registry: String, name name: String, labels labels: List(String), func func: fn() -> a, ) -> Result(a, String) ``` -------------------------------- ### set_gauge function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/gauge.html Function signature for setting the value of a gauge metric. Takes registry, name, labels, and value, and returns a Result. ```gleam pub fn set_gauge( registry registry: String, name name: String, labels labels: List(String), value value: Int, ) -> Result(Nil, String) ``` -------------------------------- ### linear function definition Source: https://hexdocs.pm/promgleam/promgleam/buckets.html Defines the linear function signature for generating histogram buckets. ```gleam pub fn linear( start start: Float, step step: Float, count count: Int, ) -> Result(List(Float), String) ``` -------------------------------- ### measure_histogram_seconds Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Measures a function execution time in seconds and observes that in the Histogram. ```APIDOC ## measure_histogram_seconds ### Description Measures a function execution time in seconds and observes that in the Histogram. ### Function Signature ```gleam pub fn measure_histogram_seconds( registry registry: String, name name: String, labels labels: List(String), func func: fn() -> a, ) -> Result(a, String) ``` ### Parameters - `registry` (String) - Required - The registry to use. - `name` (String) - Required - The name of the histogram metric. - `labels` (List(String)) - Required - List of label values for the observation. - `func` (fn() -> a) - Required - The function to measure. ### Returns - `Result(a, String)` - Ok(the function's return value) on success, or Error(String) on failure. ### Example ```gleam 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() ``` ```gleam 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: _ ) ``` ``` -------------------------------- ### set_gauge Source: https://hexdocs.pm/promgleam/promgleam/metrics/gauge.html Sets the value of the Gauge. ```APIDOC ## set_gauge ### Description Sets the value of the Gauge. ### Function Signature pub fn set_gauge(registry: String, name: String, labels: List(String), value: Int) -> Result(Nil, String) ### Parameters - **registry** (String) - Required - The registry containing the gauge. - **name** (String) - Required - The name of the gauge metric. - **labels** (List(String)) - Required - List of label values identifying the gauge. - **value** (Int) - Required - The value to set the gauge to. ### Return Value Result(Nil, String) - Returns Ok(Nil) on success, or an error string on failure. ### Example ```gleam set_gauge( registry: "default", name: "cache_size", labels: [ "image_cache" ], value: 123, ) ``` ``` -------------------------------- ### observe_histogram function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html The signature for observing a specific value in a histogram. ```gleam pub fn observe_histogram( registry registry: String, name name: String, labels labels: List(String), value value: Float, ) -> Result(Nil, String) ``` -------------------------------- ### increment_counter function signature Source: https://hexdocs.pm/promgleam/promgleam/metrics/counter.html Defines the increment_counter function that increments a counter by a given value. It takes a registry name, metric name, label values, and an integer value, returning a Result. ```gleam pub fn increment_counter( registry registry: String, name name: String, labels labels: List(String), value value: Int, ) -> Result(Nil, String) ``` -------------------------------- ### clear_registry Source: https://hexdocs.pm/promgleam/promgleam/registry.html Removes all previously registered metrics from a specified registry. ```APIDOC ## clear_registry ### Description Removes all the previously registered metrics from a registry. ### Function Signature pub fn clear_registry(name: String) -> Nil ### Parameters - **name** (String) - The name of the registry to clear. ### Return Value Nil ``` -------------------------------- ### measure_histogram Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Measures a function execution time in milliseconds and observes that in the Histogram. ```APIDOC ## measure_histogram ### Description Measures a function execution time in milliseconds and observes that in the Histogram. ### Function Signature ```gleam pub fn measure_histogram( registry registry: String, name name: String, labels labels: List(String), func func: fn() -> a, ) -> Result(a, String) ``` ### Parameters - `registry` (String) - Required - The registry to use. - `name` (String) - Required - The name of the histogram metric. - `labels` (List(String)) - Required - List of label values for the observation. - `func` (fn() -> a) - Required - The function to measure. ### Returns - `Result(a, String)` - Ok(the function's return value) on success, or Error(String) on failure. ### Example ```gleam 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() ``` ```gleam 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: _ ) ``` ``` -------------------------------- ### clear_registry function signature Source: https://hexdocs.pm/promgleam/promgleam/registry.html Removes all previously registered metrics from a registry. The function takes the registry name as a String and returns Nil. ```gleam pub fn clear_registry(name: String) -> Nil ``` -------------------------------- ### measure function signature Source: https://hexdocs.pm/promgleam/promgleam/utils.html The signature for the measure function which takes a function and returns a tuple containing the execution time in milliseconds and the function's result. ```gleam pub fn measure(func: fn() -> a) -> #(Int, a) ``` -------------------------------- ### observe_histogram Source: https://hexdocs.pm/promgleam/promgleam/metrics/histogram.html Observes a value in the Histogram. ```APIDOC ## observe_histogram ### Description Observes a value in the Histogram. ### Function Signature ```gleam pub fn observe_histogram( registry registry: String, name name: String, labels labels: List(String), value value: Float, ) -> Result(Nil, String) ``` ### Parameters - `registry` (String) - Required - The registry to use. - `name` (String) - Required - The name of the histogram metric. - `labels` (List(String)) - Required - List of label values for the observation. - `value` (Float) - Required - The value to observe. ### Returns - `Result(Nil, String)` - Ok(Nil) on success, or Error(String) on failure. ### Example ```gleam observe_histogram( registry: "default", name: "http_request_duration_seconds", labels: [ "GET", "/", "200" ], value: 0.23, ) ``` ``` -------------------------------- ### Buckets type definition Source: https://hexdocs.pm/promgleam/promgleam/buckets.html The Buckets type is defined as a list of floats. ```gleam pub type Buckets = List(Float) ``` -------------------------------- ### increment_counter Source: https://hexdocs.pm/promgleam/promgleam/metrics/counter.html Increments an existing Counter metric with the given value. Returns a Result indicating success or an error string. ```APIDOC ## increment_counter ### Description Increments the Counter with the given value. ### Function Signature pub fn increment_counter( registry registry: String, name name: String, labels labels: List(String), value value: Int, ) -> Result(Nil, String) ### Parameters - **registry** (String) - Required - The registry where the counter is registered. - **name** (String) - Required - The name of the counter metric. - **labels** (List(String)) - Required - List of label values for the increment. - **value** (Int) - Required - The value to increment the counter by. ### Return Value Result(Nil, String) - Ok(Nil) on success, or Error(String) on failure. ### Example ```gleam increment_counter( registry: "default", name: "http_requests_total", labels: [ "GET", "/", "200" ], value: 1, ) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.