feat: add prometheus flask metrics

This commit is contained in:
Ana Custura 2024-12-04 13:02:01 +00:00 committed by irl
parent c50d341c26
commit 4dd0c4ed22
2 changed files with 5 additions and 1 deletions

View file

@ -20,18 +20,20 @@ from app.models.automation import Automation, AutomationState
from app.portal import portal
from app.portal.report import report
from app.tfstate import tfstate
from prometheus_flask_exporter import PrometheusMetrics
app = Flask(__name__)
app.config.from_file("../config.yaml", load=yaml.safe_load)
# create new registry to avoid multiple metrics registration in global REGISTRY
registry = CollectorRegistry()
metrics = PrometheusMetrics(app, registry=registry)
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { # type: ignore[method-assign]
'/metrics': make_wsgi_app(registry)
})
#register default collectors to our new registry
# register default collectors to our new registry
collectors = list(REGISTRY._collector_to_names.keys())
for collector in collectors:
registry.register(collector)
@ -137,6 +139,7 @@ class AutomationCollector(Collector):
ok.add_metric(["automation_state"], 0)
yield ok
# register all custom collectors to registry
if not_migrating() and 'DISABLE_METRICS' not in os.environ:
registry.register(DefinedProxiesCollector())

View file

@ -17,6 +17,7 @@ markupsafe
nose
openpyxl
prometheus_client
prometheus_flask_exporter
pytest
python-dateutil
python-gitlab