Optional
serviceName: `${string}-${string}`Generates a plain text representation of all registered Prometheus metrics and returns it as an HTTP response.
The response body is constructed by flattening each metric's help
, type
, and value
fields,
joining them with newline characters. The response is returned with a Content-Type
header
set to text/plain; version=0.0.4; charset=utf-8
, which is compatible with Prometheus exposition format.
An HTTP response containing the formatted metrics data.
Sets a counter metric with the specified name and value, optionally with a label. The counter is created with the provided parameters and registered with the current prefix.
The name of the counter metric.
The numeric value to set for the counter.
Optional
label: string(Optional) A label to associate with the counter metric.
Sets a gauge metric with the specified name and value, optionally with a label. The gauge is created with the provided parameters and registered with the current prefix.
The name of the gauge metric.
The numeric value to set for the gauge.
Optional
label: string(Optional) A label to associate with the gauge metric.
A builder class for constructing and managing Prometheus metrics.
The
PrometheusBuild
class allows you to create and register custom metrics, such as gauges, with an optional prefix for metric names. It maintains an internal registry of metrics and provides a method to output all registered metrics in the OpenMetrics text format.Remarks
printRegistries
method returns aResponse
object with all metrics formatted for Prometheus scraping.