# Monitoring Dash with Prometheus

**URL:** <https://community.plotly.com/t/monitoring-dash-with-prometheus/52255>\
**Category:** Dash Python\
**Created:** [April 22, 2021, 6:06pm UTC](https://community.plotly.com/t/monitoring-dash-with-prometheus/52255 "2021-04-22T18:06:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![naderelshehabi](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@naderelshehabi](https://community.plotly.com/u/naderelshehabi)\
**Post date:** [April 22, 2021, 6:06pm UTC](https://community.plotly.com/t/monitoring-dash-with-prometheus/52255/1 "2021-04-22T18:06:56Z")

</div>

Hello there.

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](https://pypi.org/project/prometheus-flask-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](https://dash.plotly.com/urls), 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.?

---

<div class="post-metadata">

**Author:** ![anotherbeanonthebus](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anotherbeanonthebus](https://community.plotly.com/u/anotherbeanonthebus)\
**Post date:** [September 9, 2021, 2:09pm UTC](https://community.plotly.com/t/monitoring-dash-with-prometheus/52255/2 "2021-09-09T14:09:25Z")

</div>

Hi,

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.

Thnks!

Here is a simplified abstraction of our code:

```auto
import dash
from prometheus_flask_exporter import PrometheusMetrics

app = dash.Dash( __name__ )
... (the app specifics)

server = app.server
metrics = PrometheusMetrics(server)
... (run the app)

```

---

<div class="post-metadata">

**Author:** ![naderelshehabi](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@naderelshehabi](https://community.plotly.com/u/naderelshehabi)\
**Post date:** [September 12, 2021, 4:41am UTC](https://community.plotly.com/t/monitoring-dash-with-prometheus/52255/3 "2021-09-12T04:41:39Z")

</div>

Hi there.

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 `app.py` dile:

```auto
# Detect if the server is running via gunicorn

is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "")

metrics = None

if is_gunicorn:
    metrics = GunicornPrometheusMetrics(server)
else:
    metrics = PrometheusMetrics(server, path=None)
    metrics.start_http_server(int(os.getenv('METRICS_PORT')))

```

You’llneed to make sure the following environment variables are set to the values of your choice:

```auto
PROMETHEUS_MULTIPROC_DIR=./.cache
METRICS_PORT=8000

```

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.
