Skip to content

Commit e7d74bd

Browse files
darwvin-devclaude
authored andcommitted
prometheus: align histogram docs with the other script functions
Use the same script_route and declare-before-push notes as prometheus_declare_stat() and prometheus_push_stat(), plus a Parameters list and a titled usage example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ebd7b6f commit e7d74bd

1 file changed

Lines changed: 56 additions & 24 deletions

File tree

‎modules/prometheus/README.md‎

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,34 +385,66 @@ route[my_custom_prometheus_route] {
385385

386386
#### prometheus_push_histogram_stat(value, suffix, [label_name], [label_value])
387387

388-
Pushes one pre-aggregated Prometheus histogram series for the family most
389-
recently declared by `prometheus_declare_stat(name, "histogram")` in the
390-
configured scrape script route. Supported suffixes are `_bucket`,
391-
`_sum` and `_count`. For bucket series, provide the `le` label.
392-
You can also supply an entire label block using the raw
393-
`label_name` argument, like `{le="50",gateway="gw1"}`.
394-
395-
This function **does not observe latencies or aggregate buckets**. It
396-
serializes integer values already maintained by the caller. Histogram
397-
buckets must be cumulative, include a `+Inf` bucket, and the
398-
`_count` value must equal the final bucket count. Use the same
399-
unit for `_sum` and bucket bounds.
400-
401-
```opensips
388+
389+
> [!NOTE]
390+
> This function can only be used in the
391+
> route declared in the [script_route](#script_routestring) parameter.
392+
393+
394+
Pushes one series of a pre-aggregated histogram (a bucket, the sum or
395+
the count) to the Prometheus server, using the name of the statistic
396+
most recently declared with
397+
`prometheus_declare_stat(name, "histogram")`.
398+
399+
400+
> [!NOTE]
401+
> A statistic's value should only be pushed
402+
> after it had been declared using the
403+
> [prometheus_declare_stat()](#prometheus_declare_statname-type-help) function.
404+
405+
406+
> [!NOTE]
407+
> This function is only a formatting helper: it does not observe
408+
> values or aggregate buckets, it only exports integer values already
409+
> maintained by the script. Buckets must be cumulative, include a
410+
> `+Inf` bucket, and the `_count` value must equal the `+Inf` bucket.
411+
> Use the same unit for `_sum` and for the bucket bounds.
412+
413+
414+
Parameters
415+
416+
417+
- *value* (integer) - the value of the series
418+
*suffix* (string) - the histogram series to push:
419+
*_bucket*, *_sum* or *_count*. Any other value is rejected.
420+
*label_name* (string, optional) - same as for
421+
[prometheus_push_stat()](#prometheus_push_statvalue-label_name-label_value).
422+
Bucket series must carry the *le* label.
423+
*label_value* (string, optional) - the value that
424+
should be used for the *label_name* parameter label.
425+
426+
427+
This function can only be used in the request
428+
route declared in the [script_route](#script_routestring) parameter.
429+
430+
431+
```opensips title="prometheus_push_histogram_stat usage"
432+
...
433+
modparam("prometheus", "script_route", "my_custom_prometheus_route")
434+
...
402435
route[my_custom_prometheus_route] {
403-
prometheus_declare_stat("opensips_invite_latency_ms", "histogram",
404-
"Aggregated INVITE processing latency in milliseconds");
405-
prometheus_push_histogram_stat($stat(invite_le_50), "_bucket", "le", "50");
406-
prometheus_push_histogram_stat($stat(invite_le_100), "_bucket", "le", "100");
407-
prometheus_push_histogram_stat($stat(invite_total), "_bucket", "le", "+Inf");
408-
prometheus_push_histogram_stat($stat(invite_sum_ms), "_sum");
409-
prometheus_push_histogram_stat($stat(invite_total), "_count");
436+
...
437+
prometheus_declare_stat("opensips_invite_latency_ms", "histogram",
438+
"Aggregated INVITE processing latency in milliseconds");
439+
prometheus_push_histogram_stat($stat(invite_le_50), "_bucket", "le", "50");
440+
prometheus_push_histogram_stat($stat(invite_le_100), "_bucket", "le", "100");
441+
prometheus_push_histogram_stat($stat(invite_total), "_bucket", "le", "+Inf");
442+
prometheus_push_histogram_stat($stat(invite_sum_ms), "_sum");
443+
prometheus_push_histogram_stat($stat(invite_total), "_count");
444+
...
410445
}
411446
```
412447

413-
The example assumes that the referenced statistics are already updated by
414-
the deployment. This is a formatting helper, not a built-in latency
415-
Histogram recorder.
416448

417449
### Examples
418450

0 commit comments

Comments
 (0)