Prometheus Flask exporter with __main__
See original GitHub issueI want to use Prometheus Flask exporter with __main__.
This works fine by running env FLASK_APP=app.py flask run --port=80 --host=‘0.0.0.0’:
from flask import Flask
from prometheus_flask_exporter import PrometheusMetrics
app = Flask(__name__)
metrics = PrometheusMetrics(app)
app.debug = True
@app.route("/", methods=['GET'])
def index():
return "hello world"
But I want to use my app in __main__, running python app.py.
from flask import Flask
from prometheus_flask_exporter import PrometheusMetrics
app = Flask(__name__)
metrics = PrometheusMetrics(app=None, path='/metrics')
app.debug = True
@app.route("/", methods=['GET'])
def index():
return "hello world"
if __name__ == '__main__':
metrics.init_app(app)
app.run(host='0.0.0.0', port=80)
Here I get 400 on /metrics.
I got no clue how to init metrics correctly.
thx for helping klml
PS I asked this already stackoverflow.com, but got no answer.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
prometheus-flask-exporter - PyPI
This library provides HTTP request metrics to export into Prometheus. It can also track method invocations using convenient functions. Installing. Install using ...
Read more >Monitoring Python Flask microservices with Prometheus
Learn about how easy it is to monitor your Python Flask applications with Prometheus using an exporter library!
Read more >Implement Prometheus Metrics in a Flask Application
Learn to add Prometheus Metrics to an existing Python Application, step by step. Tagged with flask, python, prometheus, tutorial.
Read more >Prometheus Flask exporter with __main__ - Stack Overflow
I want to use Prometheus Flask exporter with __main__ . But I want to use my app in __main__ , running python app.py...
Read more >Prometheus Exporter for Flask Applications - Morioh
Prometheus Flask Exporter : Prometheus Exporter for Flask Applications. This library provides HTTP request metrics to export into Prometheus.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can confirm that the debug flag seems to break things. If I put the following in
app.py
and run withpython app.py
then I see the metrics page successfully at http://127.0.0.1:5000/metricsBut change
debug=False
todebug=True
and I get a 404. This is withprometheus-flask-exporter==0.11.0
.@rycus86 thx for your lightspeed responses;)
I tried DEBUG_METRICS and it suddenly worked. It even does not depend if DEBUG_METRICS is true or false. It only must be set. Vice versa, with no DEBUG_METRICS at all, I get “my” 404.
First I tried without DEBUG_METRICS and got a 404, but I got 200 be only setting DEBUG_METRICS.
So I got a workaround;)
Thx klml