rycus86 / prometheus_flask_exporter

Prometheus exporter for Flask applications
https://pypi.python.org/pypi/prometheus-flask-exporter
MIT License
645 stars 161 forks source link

Request for help of using it #167

Open Gruummy opened 11 months ago

Gruummy commented 11 months ago

Hi to the round,

i am no developer .. i directly need so say. I am starting the evolve to a DevOps engeneer and need to extend things to make it better.

Currently we use pgadmin4 .. which is a flask .. gunicorn docker container we run.

https://github.com/pgadmin-org/pgadmin4

It uses this command to start gunicorn https://github.com/pgadmin-org/pgadmin4/blob/master/pkg/docker/entrypoint.sh#L95

exec /venv/bin/gunicorn --limit-request-line "${GUNICORN_LIMIT_REQUEST_LINE:-8190}" --timeout "${TIMEOUT}" --bind "${PGADMIN_LISTEN_ADDRESS:-[::]}:${PGADMIN_LISTEN_PORT:-80}" -w 1 --threads "${GUNICORN_THREADS:-25}" --access-logfile "${GUNICORN_ACCESS_LOGFILE:--}" -c gunicorn_config.py run_pgadmin:app

And it uses this for gunicorn config https://github.com/pgadmin-org/pgadmin4/blob/master/pkg/docker/gunicorn_config.py

import gunicorn
gunicorn.SERVER_SOFTWARE = 'Python'

And the startup happens where https://github.com/pgadmin-org/pgadmin4/blob/master/pkg/docker/run_pgadmin.py

import builtins
builtins.SERVER_MODE = True

from pgAdmin4 import app

pgadmin4 app itself is located here: https://github.com/pgadmin-org/pgadmin4/blob/master/web/pgAdmin4.py

Is there some possibility existing with some "smart" and small "tweaks" to extend / wrap the application to be able to add the metrics of flask without big rework of the main code of the application ?

Any help / hint how to do it with application would be REALLY great.

rycus86 commented 11 months ago

Hello! 👋 As the README explains you can get default metrics with a one-liner (ok, two with imports):

from prometheus_flask_exporter import PrometheusMetrics

...

metrics = PrometheusMetrics(app)

For a quick test, I'd perhaps just add it in pkg/docker/run_pgadmin.py to get default metrics on the default /metrics endpoint:

import builtins
from prometheus_flask_exporter import PrometheusMetrics
builtins.SERVER_MODE = True

from pgAdmin4 import app

metrics = PrometheusMetrics(app)

That should be it (based on a quick look).