people_counter/metrics.py
2025-08-02 03:25:54 +02:00

28 lines
790 B
Python

import threading
from prometheus_client import Counter, CollectorRegistry
_lock = threading.Lock()
_registry = None
_metrics = None
def get_metrics():
global _registry, _metrics
with _lock:
if _registry is None:
_registry = CollectorRegistry()
_metrics = {
"people_in": Counter(
"people_in_count",
"Number of people who entered",
["stream"],
registry=_registry,
),
"people_out": Counter(
"people_out_count",
"Number of people who exited",
["stream"],
registry=_registry,
),
}
return _registry, _metrics