feat: add prometheus flask metrics
This commit is contained in:
parent
c50d341c26
commit
4dd0c4ed22
2 changed files with 5 additions and 1 deletions
|
@ -20,18 +20,20 @@ from app.models.automation import Automation, AutomationState
|
||||||
from app.portal import portal
|
from app.portal import portal
|
||||||
from app.portal.report import report
|
from app.portal.report import report
|
||||||
from app.tfstate import tfstate
|
from app.tfstate import tfstate
|
||||||
|
from prometheus_flask_exporter import PrometheusMetrics
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_file("../config.yaml", load=yaml.safe_load)
|
app.config.from_file("../config.yaml", load=yaml.safe_load)
|
||||||
|
|
||||||
# create new registry to avoid multiple metrics registration in global REGISTRY
|
# create new registry to avoid multiple metrics registration in global REGISTRY
|
||||||
registry = CollectorRegistry()
|
registry = CollectorRegistry()
|
||||||
|
metrics = PrometheusMetrics(app, registry=registry)
|
||||||
|
|
||||||
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { # type: ignore[method-assign]
|
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { # type: ignore[method-assign]
|
||||||
'/metrics': make_wsgi_app(registry)
|
'/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())
|
collectors = list(REGISTRY._collector_to_names.keys())
|
||||||
for collector in collectors:
|
for collector in collectors:
|
||||||
registry.register(collector)
|
registry.register(collector)
|
||||||
|
@ -137,6 +139,7 @@ class AutomationCollector(Collector):
|
||||||
ok.add_metric(["automation_state"], 0)
|
ok.add_metric(["automation_state"], 0)
|
||||||
yield ok
|
yield ok
|
||||||
|
|
||||||
|
|
||||||
# register all custom collectors to registry
|
# register all custom collectors to registry
|
||||||
if not_migrating() and 'DISABLE_METRICS' not in os.environ:
|
if not_migrating() and 'DISABLE_METRICS' not in os.environ:
|
||||||
registry.register(DefinedProxiesCollector())
|
registry.register(DefinedProxiesCollector())
|
||||||
|
|
|
@ -17,6 +17,7 @@ markupsafe
|
||||||
nose
|
nose
|
||||||
openpyxl
|
openpyxl
|
||||||
prometheus_client
|
prometheus_client
|
||||||
|
prometheus_flask_exporter
|
||||||
pytest
|
pytest
|
||||||
python-dateutil
|
python-dateutil
|
||||||
python-gitlab
|
python-gitlab
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue