Slide 14
Slide 14 text
14
Инициализация
1 from prometheus_client import CONTENT_TYPE_LATEST, CollectorRegistry, generate_latest, multiprocess
2
3
4 class PrometheusClient:
5 HTTP_RESPONSE_TIME_BUCKETS = (
6 0.1, 0.25, 0.5, 1, 1.5, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, INF
7 )
8 # определения метрик
9 # ...
10
11 def __init__(self, path: str) -> None:
12 self.content_type = CONTENT_TYPE_LATEST
13 self.registry = CollectorRegistry()
14 multiprocess.MultiProcessCollector(
15 registry=self.registry,
16 path=path,
17 )
18
19 def expose(self) -> bytes:
20 return generate_latest(self.registry)
21
22 # где-то в самом конце __init__.py
23 prometheus = PrometheusClient(path=settings.PROMETHEUS_MULTIPROC_DIR)
24