Skip to main content

Prometheus summary with quantiles over configurable sliding time window

Project description

prometheus-summary

Prometheus summary with quantiles over configurable sliding time window

Installation

pip install prometheus-summary==0.1.2

This package can be found on PyPI.

Collecting

Basic usage

from prometheus_summary import Summary

s = Summary("request_latency_seconds", "Description of summary")
s.observe(4.7)

With labels

from prometheus_summary import Summary

s = Summary("request_latency_seconds", "Description of summary", ["method", "endpoint"])
s.labels(method="GET", endpoint="/profile").observe(1.2)
s.labels(method="POST", endpoint="/login").observe(3.4)

With custom quantiles and precisions

By default, metrics are observed for next quantile-precision pairs ((0.50, 0.05), (0.90, 0.01), (0.99, 0.001)) but you can provide your own value when creating the metric.

from prometheus_summary import Summary

s = Summary(
    "request_latency_seconds", "Description of summary",
    invariants=((0.50, 0.05), (0.75, 0.02), (0.90, 0.01), (0.95, 0.005), (0.99, 0.001)),
)
s.observe(4.7)

With custom time window settings

Typically, you don't want to have a Summary representing the entire runtime of the application, but you want to look at a reasonable time interval. Summary metrics implement a configurable sliding time window.

The default is a time window of 10 minutes and 5 age buckets, i.e. the time window is 10 minutes wide, and we slide it forward every 2 minutes, but you can configure this values for your own purposes.

from prometheus_summary import Summary

s = Summary(
    "request_latency_seconds", "Description of summary",
    # time window 5 minutes wide with 10 age buckets (sliding every 30 seconds)
    max_age_seconds=5 * 60,
    age_buckets=10,
)
s.observe(4.7)

Querying

Suppose we have a metric:

from prometheus_summary import Summary

s = Summary("request_latency_seconds", "Description of summary", ["method", "endpoint"])

To show request latency by method, endpoint and quntile use next query:

max by (method, endpoint, quantile) (request_latency_seconds)

To show only 99-th quantile:

max by (method, endpoint) (request_latency_seconds{quantile="0.99")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prometheus-summary-0.1.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

prometheus_summary-0.1.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file prometheus-summary-0.1.2.tar.gz.

File metadata

  • Download URL: prometheus-summary-0.1.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for prometheus-summary-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0651af07e26b9c389a53acf677b495bf05c974f6728b53a05ba3170992de0832
MD5 8322a185c38a69f557c0d9f305a3fb87
BLAKE2b-256 f9098536ece445fec09a7d3b15aba11cd9a4b6f88b6a38b7185724a0c4a58fc3

See more details on using hashes here.

File details

Details for the file prometheus_summary-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for prometheus_summary-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cad913007875c3f229f13f19bc52c3abe71785abed001364a7d182117a70a3c7
MD5 882157e6c52e89b0d93b8ea46d16ef67
BLAKE2b-256 74e26d61ec999462143aa8554a8d8db2ca4ff6d2ae1c037f4f50542264d66043

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page