|
| 1 | +Welcome to prometheus-summary documentation! |
| 2 | +============================================ |
| 3 | + |
| 4 | +`Prometheus-summary library <https://github.com/RefaceAI/prometheus-summary>`_ adds support of quantiles calculation for the Summary metric. |
| 5 | +It is fully compatible with the official `Python Prometheus client library <https://github.com/prometheus/client_python>`_. |
| 6 | + |
| 7 | +Installation |
| 8 | +------------ |
| 9 | + |
| 10 | +.. code-block:: console |
| 11 | +
|
| 12 | + pip install prometheus-summary==0.1.4 |
| 13 | +
|
| 14 | +This package can be found on `PyPI <https://pypi.org/project/prometheus-summary/>`_. |
| 15 | + |
| 16 | +Collecting |
| 17 | +---------- |
| 18 | + |
| 19 | +Basic usage |
| 20 | +^^^^^^^^^^^ |
| 21 | + |
| 22 | +.. code-block:: python |
| 23 | +
|
| 24 | + from prometheus_summary import Summary |
| 25 | +
|
| 26 | + s = Summary("request_latency_seconds", "Description of summary") |
| 27 | + s.observe(4.7) |
| 28 | +
|
| 29 | +Usage with labels |
| 30 | +^^^^^^^^^^^^^^^^^^^^^ |
| 31 | + |
| 32 | +.. code-block:: python |
| 33 | +
|
| 34 | + from prometheus_summary import Summary |
| 35 | +
|
| 36 | + s = Summary("request_latency_seconds", "Description of summary", ["method", "endpoint"]) |
| 37 | + s.labels(method="GET", endpoint="/profile").observe(1.2) |
| 38 | + s.labels(method="POST", endpoint="/login").observe(3.4) |
| 39 | +
|
| 40 | +Usage with custom quantiles and precisions |
| 41 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 42 | + |
| 43 | +By default, metrics are observed for the following (quantile, precision (inaccuracy)) pairs: |
| 44 | + |
| 45 | +``((0.50, 0.05), (0.90, 0.01), (0.99, 0.001))`` |
| 46 | + |
| 47 | +You can also provide your own values when creating the metric. |
| 48 | + |
| 49 | +.. code-block:: python |
| 50 | + from prometheus_summary import Summary |
| 51 | +
|
| 52 | + s = Summary( |
| 53 | + "request_latency_seconds", "Description of summary", |
| 54 | + invariants=((0.50, 0.05), (0.75, 0.02), (0.90, 0.01), (0.95, 0.005), (0.99, 0.001)), |
| 55 | + ) |
| 56 | + s.observe(4.7) |
| 57 | +
|
| 58 | +Usage with custom time window settings |
| 59 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 60 | + |
| 61 | +Typically, you don't want to have a Summary representing the entire runtime of the application, |
| 62 | +but you want to look at a reasonable time interval. This Summary metric implement a configurable sliding time window. |
| 63 | + |
| 64 | +The default is a time window of 10 minutes and 5 age buckets, i.e. the time window is 10 minutes wide, and |
| 65 | +we slide it forward every 10 / 5 = 2 minutes, but you can configure this values for your own purposes. |
| 66 | + |
| 67 | +.. code-block:: python |
| 68 | + from prometheus_summary import Summary |
| 69 | +
|
| 70 | + s = Summary( |
| 71 | + "request_latency_seconds", "Description of summary", |
| 72 | + # time window 5 minutes wide with 10 age buckets (sliding every 30 seconds) |
| 73 | + max_age_seconds=5 * 60, |
| 74 | + age_buckets=10, |
| 75 | + ) |
| 76 | + s.observe(4.7) |
| 77 | +
|
| 78 | +Querying |
| 79 | +-------- |
| 80 | + |
| 81 | +Suppose we have a metric: |
| 82 | + |
| 83 | +.. code-block:: python |
| 84 | +
|
| 85 | + from prometheus_summary import Summary |
| 86 | +
|
| 87 | + s = Summary("request_latency_seconds", "Description of summary", ["method", "endpoint"]) |
| 88 | +
|
| 89 | +To show request latency by `method`, `endpoint` and `quantile` use the following PromQL query: |
| 90 | + |
| 91 | +.. code-block:: promql |
| 92 | +
|
| 93 | + max by (method, endpoint, quantile) (request_latency_seconds) |
| 94 | +
|
| 95 | +To show only 99-th quantile: |
| 96 | + |
| 97 | +.. code-block:: promql |
| 98 | +
|
| 99 | + max by (method, endpoint) (request_latency_seconds{quantile="0.99"}) |
0 commit comments