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