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
