Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ def f():
# Count only one type of exception
with c.count_exceptions(ValueError):
pass

You can also reset the counter to zero in case your logical "process" restarts
without restarting the actual python process.

c.reset()

"""
_type = 'counter'

Expand All @@ -310,6 +316,11 @@ def inc(self, amount: float = 1, exemplar: Optional[Dict[str, str]] = None) -> N
_validate_exemplar(exemplar)
self._value.set_exemplar(Exemplar(exemplar, amount, time.time()))

def reset(self) -> None:
"""Reset the metric to zero."""
Comment thread
positron96 marked this conversation as resolved.
Outdated
self._value.set(0)
self._created = time.time()

def count_exceptions(self, exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]] = Exception) -> ExceptionCounter:
"""Count exceptions in a block of code or function.

Expand Down