---
title: "Configure Express exporter to generate Prometheus metrics | Grafana Cloud documentation"
description: "Set up the Express Middleware exporter"
---

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

# Configure Express exporter to generate Prometheus metrics

This topic describes how to configure the Express Middleware exporter.

To configure the Express exporter to generate Prometheus metrics, complete the following steps.

1. Add the Express exporter as a dependency in your NodeJS package.json.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   {
     ...
     "dependencies": {
         ...
         "express-prometheus-middleware": "1.2.0"
     }
   }
   ```
2. Import the package and add it to the Express application.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   ...
   const promMid = require('express-prometheus-middleware');
   ...
   
   app.use(promMid({
       metricsPath: '/metrics',
       collectDefaultMetrics: true,
       requestDurationBuckets: [0.1, 0.5, 1, 3, 5, 10],
       /**
        * Uncommenting the `authenticate` callback makes the `metricsPath` route
        * require authentication. This authentication callback can make a
        * basic auth test, or even query a remote server to validate access.
        * To access /metrics you could do:
        * curl -X GET user:password@localhost:9091/metrics
        */
       // authenticate: req => req.headers.authorization === 'Basic dXNlcjpwYXNzd29yZA==',
       /**
        * Uncommenting the `extraMasks` configuration uses the list of regexes to
        * reformat URL path names and replace the values found with a placeholder value
       */
       // extraMasks: [/..:..:..:..:..:../],
       /**
        * The prefix option causes all metrics to have the given prefix.
        * E.g.: `app_prefix_http_requests_total`
        */
       // prefix: 'app_prefix_',
       /**
        * Can add custom labels with customLabels and transformLabels options
        */
       // customLabels: ['contentType'],
       // transformLabels(labels, req) {
       //   // eslint-disable-next-line no-param-reassign
       //   labels.contentType = req.headers['content-type'];
       // },
      }));
   ```
3. If the request URLs include IDs, for example, **GET /order/1234567**, capture the URLs as **/order/{id}** to avoid metric explosion.
   
   In the following example, the regexp **\[0-9]+**, which captures numbers **1234567**, can be specified in the **extraMasks** list of regular expressions.
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   extraMasks: ['[0-9]+']
   ```
4. Verify the presence of the following metrics:
   
   - http\_requests\_total
   - http\_request\_duration\_seconds\_count
   - http\_request\_duration\_seconds\_sum
   - http\_request\_duration\_seconds\_bucket

## Metrics

|                                                                     |                                                                                                                                                                                                                                                                                                                                         |
|---------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Metric**                                                          | **KPI**                                                                                                                                                                                                                                                                                                                                 |
| **Requests**<br /><br /><br /><br />http\_requests\_total           | Request Rate<br /><br /><br /><br />rate(http\_requests\_total\[5m])                                                                                                                                                                                                                                                                    |
| **Errors**<br /><br /><br /><br />http\_requests\_total             | Error Ratio (server errors)<br /><br /><br /><br />rate(http\_requests\_total{status=~"5.."}\[5m])/ rate(http\_requests\_total\[5m])<br /><br /><br /><br />Error Ratio (client errors)<br /><br /><br /><br />rate(http\_requests\_total{statusCode=~"4.."}\[5m])/ rate(http\_requests\_total\[5m])                                    |
| **Latency**<br /><br /><br /><br />http\_request\_duration\_seconds | Latency Average<br /><br /><br /><br />rate(http\_request\_duration\_seconds\_sum\[5m])/ rate(http\_request\_duration\_seconds\_count\[5m])<br /><br /><br /><br />Latency P99<br /><br /><br /><br />histogram\_quantile (  <br />0.99,  <br />sum(rate(http\_request\_duration\_seconds\_bucket\[1m]) &gt; 0)  <br />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 from resources and requests:

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