Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gunicorn flask metrics exporting #169

Open
vinur1992 opened this issue Jan 9, 2024 · 3 comments
Open

Gunicorn flask metrics exporting #169

vinur1992 opened this issue Jan 9, 2024 · 3 comments

Comments

@vinur1992
Copy link

I have flask application with views and main app. i need export metrics from these views. i tried everything as per example. but i only get # HELP by_endpoint_counter_total Request count by endpoints

TYPE by_endpoint_counter_total counter. not any values. I need set up number of hits on each route and export it into another port. please help. application running in gunicorn server

@rycus86
Copy link
Owner

rycus86 commented Jan 9, 2024

Have you checked the https://github.com/rycus86/prometheus_flask_exporter/tree/master/examples/gunicorn example? That one runs Gunicorn on port 4000 but exposes the metrics on port 9200, which sounds like you're after?
If this doesn't help, could you post a (minimal) example of how you're setting things up so we can see what might be going wrong?

@vinur1992
Copy link
Author

from flask import Blueprint,request,jsonify,Response,render_template,current_app
import os
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics

os.environ["PROMETHEUS_MULTIPROC_DIR"]="/home/u1437/Ospyn/Chosonbox/dedupe/CDS-AI"
print(os.environ)
metrics = GunicornPrometheusMetrics.for_app_factory()

app_bp=Blueprint('dedupe_blueprint', name,static_folder='static',template_folder='templates')

@app_bp.route('/test')
def index():
return 'Hello world'

@app_bp.route('/error')
def error():
raise Exception('Fail')
this is views.py inside folder blueprints
from flask import Flask,request,current_app
from Blueprints.views import app_bp
def main_app():
app = Flask(name)
#metrics.init_app(app)
app.register_blueprint(app_bp,url_prefix="/")
return app
app=main_app()
if name == 'main':
app.run(debug=False) this is main.py outside blueprint folder

this is gunicorn_config.py
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics

def when_ready(server):
GunicornPrometheusMetrics.start_http_server_when_ready(8080)
def child_exit(server, worker):
GunicornPrometheusMetrics.mark_process_dead_on_child_exit(worker.pid)
workers =2

i need to export each routes metrics via port 8080

@vinur1992 vinur1992 reopened this Jan 11, 2024
@rycus86
Copy link
Owner

rycus86 commented Jan 11, 2024

Can you try adding some debug statements (or breakpoint) in the when_ready to see if that's called as expected?
What do you get when you try accessing /metrics on port 8080? Do you get some metrics but not all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants