feat: run with gunicorn instead of flask

Each worker now uses its own registry instead of the global REGISTRY
to avoid duplicate metric registration, since metrics are served
from the database.
This commit is contained in:
Ana Custura 2024-12-02 14:21:39 +00:00
parent 45823b02e4
commit 0867b13f8f
3 changed files with 17 additions and 7 deletions

View file

@ -5,7 +5,7 @@ from typing import Iterator
import yaml
from flask import Flask, redirect, url_for, send_from_directory
from flask.typing import ResponseReturnValue
from prometheus_client import make_wsgi_app, REGISTRY, Metric
from prometheus_client import make_wsgi_app, Metric, CollectorRegistry
from prometheus_client.metrics_core import GaugeMetricFamily, CounterMetricFamily
from prometheus_client.registry import Collector
from sqlalchemy import text
@ -106,9 +106,10 @@ class AutomationCollector(Collector):
if not_migrating() and 'DISABLE_METRICS' not in os.environ:
REGISTRY.register(DefinedProxiesCollector())
REGISTRY.register(BlockedProxiesCollector())
REGISTRY.register(AutomationCollector())
registry = CollectorRegistry()
registry.register(DefinedProxiesCollector())
registry.register(BlockedProxiesCollector())
registry.register(AutomationCollector())
@app.route('/ui')