---
title: "Configure Loopback to generate Prometheus metrics | Grafana Cloud documentation"
description: "Enable Loopback metrics"
---

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

# Configure Loopback to generate Prometheus metrics

To configure Loopback to generate Prometheus metrics, complete the following steps:

1. Run the following commands:
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   Install
   --------
   npm install --save @loopback/metrics
   
   Import
   --------
   import {MetricsComponent} from '@loopback/metrics';
   ```
2. In the constructor, add the following component to your application:
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   this.component(MetricsComponent);
   ```
   
   For more information about additional configuration changes, refer to [loopback-metrics](https://github.com/loopbackio/loopback-next/tree/master/extensions/metrics).
3. Verify the presence of the following metrics in Prometheus:
   
   - loopback\_invocation\_total
   - loopback\_invocation\_duration\_seconds

## Metrics

Expand table

| **Metric**                                                             | **KPI**                                                                                                                                                                                                                                                                                                                                |
|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Requests<br /><br /><br /><br />loopback\_invocation\_total            | Request Rate<br /><br /><br /><br />rate(loopback\_invocation\_total\[5m])                                                                                                                                                                                                                                                             |
| Errors<br /><br /><br /><br />loopback\_invocation\_total              | Error Ratio (server errors)<br /><br /><br /><br />rate(loopback\_invocation\_total{status=“5..”}\[5m])/ rate(loopback\_invocation\_total\[5m])<br /><br /><br /><br />Error Ratio (client errors)<br /><br /><br /><br />rate(loopback\_invocation\_total{statusCode=“4..”}\[5m])/ rate(loopback\_invocation\_total\[5m])             |
| Latency<br /><br /><br /><br />loopback\_invocation\_duration\_seconds | Latency Average<br /><br /><br /><br />rate(loopback\_invocation\_duration\_seconds\[5m])/ rate(loopback\_invocation\_total\[5m])<br /><br /><br /><br />Latency P99<br /><br /><br /><br />histogram\_quantile (  <br />0.99,  <br />sum(rate(loopback\_invocation\_duration\_histogram\_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
