1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
# Copyright (c) 2022 Tulir Asokan
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import Any, Callable, Generic, Iterable, TypeVar
T = TypeVar("T")
Number = int | float
class Metric:
name: str
documentation: str
unit: str
typ: str
samples: list[Any]
def add_sample(
self,
name: str,
labels: Iterable[str],
value: Any,
timestamp: Any = None,
exemplar: Any = None,
) -> None: ...
class MetricWrapperBase(Generic[T]):
def __init__(
self,
name: str,
documentation: str,
labelnames: Iterable[str] = (),
namespace: str = "",
subsystem: str = "",
unit: str = "",
registry: Any = None,
labelvalues: Any = None,
) -> None: ...
def describe(self) -> list[Metric]: ...
def collect(self) -> list[Metric]: ...
def labels(self, *labelvalues, **labelkwargs) -> T: ...
def remove(self, *labelvalues) -> None: ...
class ContextManager:
def __enter__(self) -> None: ...
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...
def __call__(self, f) -> None: ...
class Counter(MetricWrapperBase[Counter]):
def inc(self, amount: Number = 1) -> None: ...
def count_exceptions(self, exception: Exception = Exception) -> ContextManager: ...
class Gauge(MetricWrapperBase[Gauge]):
def inc(self, amount: Number = 1) -> None: ...
def dec(self, amount: Number = 1) -> None: ...
def set(self, value: Number = 1) -> None: ...
def set_to_current_time(self) -> None: ...
def track_inprogress(self) -> ContextManager: ...
def time(self) -> ContextManager: ...
def set_function(self, f: Callable[[], Number]) -> None: ...
class Summary(MetricWrapperBase[Summary]):
def observe(self, amount: Number) -> None: ...
def time(self) -> ContextManager: ...
class Histogram(MetricWrapperBase[Histogram]):
def __init__(
self,
name: str,
documentation: str,
labelnames: Iterable[str] = (),
namespace: str = "",
subsystem: str = "",
unit: str = "",
registry: Any = None,
labelvalues: Any = None,
buckets: Iterable[Number] = (),
) -> None: ...
def observe(self, amount: Number = 1) -> None: ...
def time(self) -> ContextManager: ...
class Info(MetricWrapperBase[Info]):
def info(self, val: dict[str, str]) -> None: ...
class Enum(MetricWrapperBase[Enum]):
def __init__(
self,
name: str,
documentation: str,
labelnames: Iterable[str] = (),
namespace: str = "",
subsystem: str = "",
unit: str = "",
registry: Any = None,
labelvalues: Any = None,
states: Iterable[str] = None,
) -> None: ...
def state(self, state: str) -> None: ...
def async_time(metric: Gauge | Summary | Histogram) -> Callable[[Callable], Callable]: ...
|