X7ROOT File Manager
Current Path:
/opt/hc_python/lib/python3.12/site-packages/prometheus_client
opt
/
hc_python
/
lib
/
python3.12
/
site-packages
/
prometheus_client
/
📁
..
📄
__init__.py
(1.77 KB)
📁
__pycache__
📄
asgi.py
(1.57 KB)
📁
bridge
📄
context_managers.py
(2.29 KB)
📄
core.py
(860 B)
📄
decorator.py
(15.43 KB)
📄
exposition.py
(25.56 KB)
📄
gc_collector.py
(1.48 KB)
📄
metrics.py
(27.45 KB)
📄
metrics_core.py
(15.18 KB)
📄
mmap_dict.py
(5.27 KB)
📄
multiprocess.py
(7.36 KB)
📁
openmetrics
📄
parser.py
(7.26 KB)
📄
platform_collector.py
(1.83 KB)
📄
process_collector.py
(3.77 KB)
📄
py.typed
(0 B)
📄
registry.py
(6.05 KB)
📄
samples.py
(1.65 KB)
📁
twisted
📄
utils.py
(594 B)
📄
values.py
(4.88 KB)
Editing: context_managers.py
from timeit import default_timer from types import TracebackType from typing import ( Any, Callable, Literal, Optional, Tuple, Type, TYPE_CHECKING, TypeVar, Union, ) from .decorator import decorate if TYPE_CHECKING: from . import Counter F = TypeVar("F", bound=Callable[..., Any]) class ExceptionCounter: def __init__(self, counter: "Counter", exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]]) -> None: self._counter = counter self._exception = exception def __enter__(self) -> None: pass def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> Literal[False]: if isinstance(value, self._exception): self._counter.inc() return False def __call__(self, f: "F") -> "F": def wrapped(func, *args, **kwargs): with self: return func(*args, **kwargs) return decorate(f, wrapped) class InprogressTracker: def __init__(self, gauge): self._gauge = gauge def __enter__(self): self._gauge.inc() def __exit__(self, typ, value, traceback): self._gauge.dec() def __call__(self, f: "F") -> "F": def wrapped(func, *args, **kwargs): with self: return func(*args, **kwargs) return decorate(f, wrapped) class Timer: def __init__(self, metric, callback_name): self._metric = metric self._callback_name = callback_name def _new_timer(self): return self.__class__(self._metric, self._callback_name) def __enter__(self): self._start = default_timer() return self def __exit__(self, typ, value, traceback): # Time can go backwards. duration = max(default_timer() - self._start, 0) callback = getattr(self._metric, self._callback_name) callback(duration) def labels(self, *args, **kw): self._metric = self._metric.labels(*args, **kw) def __call__(self, f: "F") -> "F": def wrapped(func, *args, **kwargs): # Obtaining new instance of timer every time # ensures thread safety and reentrancy. with self._new_timer(): return func(*args, **kwargs) return decorate(f, wrapped)
Upload File
Create Folder