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

Method observe

prometheus_client/metrics.py:544–556  ·  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)

Source from the content-addressed store, hash-verified

542 self._created = time.time()
543
544 def observe(self, amount: float) -> None:
545 """Observe the given amount.
546
547 The amount is usually positive or zero. Negative values are
548 accepted but prevent current versions of Prometheus from
549 properly detecting counter resets in the sum of
550 observations. See
551 https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations
552 for details.
553 """
554 self._raise_if_not_observable()
555 self._count.inc(1)
556 self._sum.inc(amount)
557
558 def time(self) -> Timer:
559 """Time a block of code or function, and observe the duration in seconds.

Callers 15

test_summary_addsMethod · 0.95
test_summaryMethod · 0.95
__init__.pyFile · 0.45
test_collectMethod · 0.45
test_summaryMethod · 0.45
test_summaryMethod · 0.45
test_histogramMethod · 0.45
test_labelsMethod · 0.45

Calls 2

incMethod · 0.45

Tested by 15

test_summary_addsMethod · 0.76
test_summaryMethod · 0.76
test_collectMethod · 0.36
test_summaryMethod · 0.36
test_summaryMethod · 0.36
test_histogramMethod · 0.36
test_labelsMethod · 0.36