Observe the given amount. The amount is usually positive or zero. Negative values are accepted but prevent current versions of Prometheus from properly detecting counter resets in the sum of observations. See https://prometheus.io/docs/practices/histograms/#c
(self, amount: float, exemplar: Optional[Dict[str, str]] = None)
| 663 | ) |
| 664 | |
| 665 | def observe(self, amount: float, exemplar: Optional[Dict[str, str]] = None) -> None: |
| 666 | """Observe the given amount. |
| 667 | |
| 668 | The amount is usually positive or zero. Negative values are |
| 669 | accepted but prevent current versions of Prometheus from |
| 670 | properly detecting counter resets in the sum of |
| 671 | observations. See |
| 672 | https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations |
| 673 | for details. |
| 674 | """ |
| 675 | self._raise_if_not_observable() |
| 676 | self._sum.inc(amount) |
| 677 | for i, bound in enumerate(self._upper_bounds): |
| 678 | if amount <= bound: |
| 679 | self._buckets[i].inc(1) |
| 680 | if exemplar: |
| 681 | _validate_exemplar(exemplar) |
| 682 | self._buckets[i].set_exemplar(Exemplar(exemplar, amount, time.time())) |
| 683 | break |
| 684 | |
| 685 | def time(self) -> Timer: |
| 686 | """Time a block of code or function, and observe the duration in seconds. |