MCPcopy Index your code
hub / github.com/prometheus/client_python / observe

Method observe

prometheus_client/metrics.py:665–683  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 6

test_histogram_addsMethod · 0.95
test_histogramMethod · 0.95
test_histogramMethod · 0.95
test_histogramMethod · 0.95

Calls 6

_validate_exemplarFunction · 0.85
ExemplarClass · 0.85
incMethod · 0.45
set_exemplarMethod · 0.45
timeMethod · 0.45

Tested by 6

test_histogram_addsMethod · 0.76
test_histogramMethod · 0.76
test_histogramMethod · 0.76
test_histogramMethod · 0.76