prometheus.Histogram.observe()

Records a single observation (or measurement) for a histogram metric in the appropriate bucket for the specified label values.

Syntax

Note:

In this syntax diagram, the square brackets ([ ]) are part of the syntax.

observe( value FLOAT, [ labels ] )
  1. value is a value of type FLOAT to observe (for example, a duration or size).
  2. labels is a list of label values matching the histogram's label names (use [] if none).

Usage

Use the prometheus.Histogram.observe() method to observe a value in the histogram metric.
  • Call once per request/response you want to measure (typically just before sending the response).
  • Use floats; the value is placed into the configured buckets and also contributes to the histogram's sum and count.
This method is typically used for tracking distributions such as request durations or response sizes.

Example


-- Define the histogram variable
DEFINE histogram prometheus.Histogram
-- Create a histogram metric
LET histogram = prometheus.Histogram.create("histogram_hello", "a histogram", [0.25,0.75,0.9], 
                                            ["labela", "labelb"])
-- Observe a value
CALL histogram.observe(5.2, ["valuea", "valueb"])