[英]prometheus_client custom metrics with Flask
I am trying to service custom Prometheus metrics through Flask.我正在尝试通过 Flask 为自定义 Prometheus 指标提供服务。 Lookingg at https://github.com/prometheus/client_python , I have a code similar to:看着https://github.com/prometheus/client_python ,我有一个类似于:
from flask import Flask
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from prometheus_client import make_wsgi_app
# Create my app
app = Flask(__name__)
# Add prometheus wsgi middleware to route /metrics requests
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
'/metrics': make_wsgi_app()
})
With this setup, I'm not really sure where I should declare my custom metrics?通过这种设置,我不确定应该在哪里声明我的自定义指标?
Solved the issue by registering my custom collector to the REGISTRY with通过将我的自定义收集器注册到 REGISTRY 解决了这个问题
REGISTRY.register(CustomCollector())
and then using然后使用
DispatcherMiddleware(
app.wsgi_app, {"/metrics": make_wsgi_app(REGISTRY),}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.