Reputation: 1766
I 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.
Upvotes: 1
Views: 3488
Reputation: 1766
I got help on gitlab from maintainer rycus86
You have to set env DEBUG_METRICS on any value (true/false). It just must not be empty.
export DEBUG_METRICS=false
Upvotes: 1