Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions taskiq/middlewares/prometheus_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(

logger.debug(f"Setting up multiproc dir to {metrics_path}")

os.environ["PROMETHEUS_MULTIPROC_DIR"] = str(metrics_path)
os.environ["PROMETHEUS_MULTIPROC_DIR"] = str(metrics_path)

logger.debug("Initializing metrics")
Expand Down Expand Up @@ -85,11 +84,23 @@ def startup(self) -> None:
This function starts prometheus server.
It starts it only in case if it's a worker process.
"""
from prometheus_client import start_http_server # noqa: PLC0415
from prometheus_client import ( # noqa: PLC0415
CollectorRegistry,
start_http_server,
)
from prometheus_client.multiprocess import ( # noqa: PLC0415
MultiProcessCollector,
)

if self.broker.is_worker_process:
try:
start_http_server(port=self.server_port, addr=self.server_addr)
registry = CollectorRegistry()
MultiProcessCollector(registry)
start_http_server(
port=self.server_port,
addr=self.server_addr,
registry=registry,
)
except OSError as exc:
logger.debug("Cannot start prometheus server: %s", exc)

Expand Down