I’ve a Dash app deployed as a container. I’m trying to monitor the app metrics for the underlying Flask app using prometheus. I’ve installed Prometheus Exporter with no issues, and followed the instructions to init the exporter for Flask using the server.
My app is very close to this example in the official documentation , where I have a Location component to manage routing through a callback.
The problem is that when I try to visit the “/metrics” route of course, it’s caught by Dash routing logic through my callback.
Is there any way I can exclude a certain route from triggering my callback -I’m not looking for raise PreventUpdate here-?
Otherwise, what’s the best way to monitor my containerized app using Prometheus for metrics like request latency, error codes, response status, etc.?
I have a related question, and I was hoping for more information on this topic.
We are trying to monitor our containerised and deployed dash app using Prometheus, following the idea that underneath Dash there is a Flask app. Our app is a one single page for the moment. However, when using the prometheus-flask-exporter, we can’t not access the default /metrics, nor we see any default metrics being recorded.
I wonder if anyone else around here has tried monitoring their dash apps using Prometheus.
Here is a simplified abstraction of our code:
from prometheus_flask_exporter import PrometheusMetrics
app = dash.Dash(__name__)
... (the app specifics)
server = app.server
metrics = PrometheusMetrics(server)
... (run the app)
Not sure if this would help. I had two challenges with the exporter. First is avoiding the metric endpoint being caught by Dash router. So I published it using a different port.
The other thing is when debugging I’m using Flask server, but when publishing to production we were using gunicorn. So I had to account for that. Here is my working code in the
# Detect if the server is running via gunicorn
is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")
metrics = None
metrics = GunicornPrometheusMetrics(server)
metrics = PrometheusMetrics(server, path=None)
You’llneed to make sure the following environment variables are set to the values of your choice:
The first one is where the temp files are stored, while the second one is the published port that you can access the metrics endpoint on.
I hope this helps.