| 1 | --- |
| 2 | title: Histogram |
| 3 | weight: 4 |
| 4 | --- |
| 5 | |
| 6 | Histograms track the size and number of events in buckets. |
| 7 | This allows for aggregatable calculation of quantiles. |
| 8 | |
| 9 | ```python |
| 10 | from prometheus_client import Histogram |
| 11 | h = Histogram('request_latency_seconds', 'Description of histogram') |
| 12 | h.observe(4.7) # Observe 4.7 (seconds in this case) |
| 13 | ``` |
| 14 | |
| 15 | The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds. |
| 16 | They can be overridden by passing `buckets` keyword argument to `Histogram`. |
| 17 | |
| 18 | There are utilities for timing code: |
| 19 | |
| 20 | ```python |
| 21 | @h.time() |
| 22 | def f(): |
| 23 | pass |
| 24 | |
| 25 | with h.time(): |
| 26 | pass |
| 27 | ``` |