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 ] )
- value is a value of type FLOAT to observe (for example, a duration or size).
- labels is a comma-separated list of label values inside
square brackets, one for each label name declared when the metric was created, in the same order.
Where the metric declares no label names, use empty brackets
[].
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.
["url", "status"] declared, observe(0.42, ["/orders", "ok"])
records an observation for that URL and status.Example
-- Define the histogram variable
DEFINE histogram prometheus.Histogram
-- Create a histogram metric
LET histogram = prometheus.Histogram.create("histogram_request_duration",
"request duration in seconds", [0.25,0.5,1],
["url", "status"])
-- Observe a value
CALL histogram.observe(0.42, ["/orders", "ok"])