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