---
title: "Configure Flask to generate Prometheus metrics | Grafana Cloud documentation"
description: "Enable Flask to emit default metrics"
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Configure Flask to generate Prometheus metrics

Flask is a python module that you can enable for Prometheus metrics using [Flask Exporter](https://github.com/rycus86/prometheus_flask_exporter) for Prometheus.

To configure Flask to generate Prometheus metrics, perform the following steps:

1. Add the following export code in the Python module.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   from prometheus_flask_exporter import PrometheusMetrics
   ```
2. To enable custom metrics, follow the steps provided in [prometheus\_flask\_exporter](https://github.com/rycus86/prometheus_flask_exporter).
3. Verify the presence of the following metrics in Prometheus:
   
   - flask\_http\_request\_duration\_seconds
   - flask\_http\_request\_total

## Metrics

Expand table

| Metric                                                                                                                                               | Key Performance Indicator(KPI)                                                                                                                                                                                                                                                                                                      |
|------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Requests<br /><br /><br /><br />flask\_http\_request\_duration\_seconds\_count                                                                       | Request Rate<br /><br /><br /><br />rate(flask\_http\_request\_duration\_seconds\_count\[5m])                                                                                                                                                                                                                                       |
| Errors<br /><br /><br /><br />flask\_http\_request\_duration\_seconds\_count                                                                         | Error Ratio<br /><br /><br /><br />rate(flask\_http\_request\_duration\_seconds\_count{status=~“5..”}\[5m])/ rate(flask\_http\_request\_duration\_seconds\_count\[5m])                                                                                                                                                              |
| Latency<br /><br /><br /><br />flask\_http\_request\_duration\_seconds\_bucket<br /><br /><br /><br />flask\_http\_request\_duration\_seconds\_count | Latency Average<br /><br /><br /><br />rate(flask\_http\_request\_duration\_seconds\_count\[5m])/ rate(flask\_http\_request\_duration\_seconds\_count\[5m])<br /><br /><br /><br />Latency P99<br /><br /><br /><br />```<br />histogram_quantile (0.99,sum(rate(flask_http_request_duration_seconds_bucket[1m])) by (le))<br />``` |

## Alerts

Expand table

| **KPI**                                            | **Alerts**                                                                                                                  |
|----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| Request Rate                                       | **RequestRateAnomaly**                                                                                                      |
| Error Rate                                         | **ErrorRatioBreach**<br /><br /><br /><br />**ErrorBuildup** based on a 99.9 SLO                                            |
| Latency Average<br /><br /><br /><br />Latency P99 | **LatencyAverageBreach**<br /><br /><br /><br />**LatencyAverageAnomaly**<br /><br /><br /><br />**LatencyP99ErrorBuildup** |

## Service KPI dashboard

This dashboard has the following KPIs that include resource and requests metrics:

- Request Rate
- Latency Average
- Latency P99
- Error Rate
- CPU %
- CPU Cores Used
- CPU Throttle
- Memory %
- Memory Bytes
- Disk Usage
- Network Usage

You can include any custom dashboard from the community. For example, [this dashboard](https://github.com/rycus86/prometheus_flask_exporter/blob/master/examples/sample-signals/grafana/dashboards/example.json) shows Flask specific metrics directly as a custom dashboard for your service.
