---
title: "Best Practices of Integrating Prometheus with APISIX - API7.ai"
description: "This article will introduce how to configure and use Prometheus in Apache APISIX and recommend some common indicator configurations."
url: "https://api7.ai/blog/best-practice-for-integrating-apisix-with-prometheus"
---

[Blog](https://api7.ai/blog)

[Products](https://api7.ai/category/products)[Technology](https://api7.ai/category/technology)[Ecosystem](https://api7.ai/category/ecosystem)[Case Study](https://api7.ai/category/usercase)[Team & Community](https://api7.ai/category/community)

Search

⌘ + K

[Blog](https://api7.ai/blog)

Technology

# Best Practices of Integrating Prometheus with APISIX

January 13, 2024

[Technology](https://api7.ai/category/technology)

In today's cloud-native architecture, monitoring the [metrics](https://api7.ai/blog/api7-portal-monitor-api-metrics) of your API gateway is crucial. Apache APISIX, serving as a high-performance API gateway, not only offers extensive functionalities but also supports seamless integration with Prometheus to collect and monitor key API traffic metrics. This article explores how to configure and use Prometheus in Apache APISIX, highlighting essential considerations and recommending common metric configurations.

### About Prometheus

[Prometheus](https://apisix.apache.org/docs/apisix/plugins/prometheus/) is an open-source monitoring system that collects and stores time-series data, enabling real-time monitoring and analysis of system performance. When integrated with Apache APISIX, Prometheus becomes instrumental in capturing fine-grained metrics related to API traffic.

### Enabling Prometheus Plugin in Apache APISIX

1. To enable Prometheus metrics in Apache APISIX, start by configuring the Prometheus plugin in the `config.yaml` file:

   ```
   plugins:
     - prometheus
   ```

2. Configure the Prometheus plugin on the desired service or API to be collected. Alternatively, configure it globally. Here's an example of configuring the plugin using a cURL command:

   ```
   curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "uri": "/hello",
       "plugins": {
           "prometheus":{}
       },
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:80": 1
           }
       }
   }'
   ```

   For more complex configurations, refer to: [Prometheus Plugin Documentation](https://apisix.apache.org/docs/apisix/plugins/prometheus/)

### Configuring Collection Strategy in Prometheus

In Prometheus, configure the `prometheus.yml` file to add APISIX as a new monitoring target:

```
scrape_configs:
  - job_name: 'apisix'
    static_configs:
    - targets: ['<APISIX_IP>:<APISIX_PORT>']
```

### Common Metrics in Apache APISIX

Enterprise-specific metrics may vary, but here are some key metrics in Apache APISIX, providing rich information for system monitoring and analysis:

- **HTTP Request and Response Metrics:**

  - `apisix_http_request_total`: Records the total HTTP requests through APISIX, offering an overview of system traffic.
  - `apisix_http_request_duration_seconds`: Measures HTTP request processing time, aiding in identifying performance bottlenecks.
  - `apisix_http_request_size_bytes`: Captures the size of HTTP requests for data analysis.
  - `apisix_http_response_size_bytes`: Monitors the size of HTTP responses to track response data volume.

- **Upstream Service Metrics:**

  - `apisix_upstream_latency`: Reflects the response latency of upstream services.
  - `apisix_upstream_health`: Indicates the health status of upstream services.

- **System Performance Metrics:**

  - `apisix_node_cpu_usage`: Reports the CPU usage of the APISIX node.
  - `apisix_node_memory_usage`: Offers insights into memory usage.

- **Traffic Metrics:**

  - `apisix_bandwidth`: Details the bandwidth usage for both upstream and downstream traffic.

- **Error and Exception Metrics:**

  - `apisix_http_status_code`: Distributes HTTP response status codes, particularly focusing on 4xx and 5xx errors.

### Visualization and Alerts

Leverage Grafana and Prometheus integration to create dashboards for visualizing these metrics. Additionally, Prometheus alerting rules can be configured to set up alerts based on specific conditions.

**Grafana Dashboard Example:** Create various charts in Grafana, such as time series, bar graphs, or pie charts, to showcase APISIX's performance metrics. For instance, a dashboard displaying HTTP request counts and average response times offers real-time traffic and performance insights.

**Prometheus Alerting Example:** Alerting rules in Prometheus can be configured for various conditions. For instance, if the average duration of `apisix_http_request_duration_seconds` surpasses a predefined threshold, Prometheus can be configured to send critical alerts.

## Optimization Considerations

While having extensive Prometheus metrics enhances monitoring and alerting dimensions, it's crucial to acknowledge that these metrics consume computational resources. More metrics imply higher resource demands, potentially impacting business systems.

Since version 3.0, Apache APISIX has significantly optimized the Prometheus plugin, introducing a dedicated process for metric statistics and retrieval. This improvement mitigates the impact on business traffic caused by extensive Prometheus metric statistics, which was contributed by [API7.ai](https://api7.ai/).

## Conclusion

By integrating Prometheus with Apache APISIX, enterprises gain profound insights into their API infrastructure, ensuring efficient and secure operations. API traffic monitoring gradually becomes an essential tool for proactively preventing issues, optimizing performance, and ensuring security.

Tags:

[Monitoring](https://api7.ai/tags/monitoring)

[APISIX Basics](https://api7.ai/tags/apisix-basics)

Share article link

Share

Related Posts

[![API Health Check Methods and Best Practices](https://static.api7.ai/uploads/2026/04/07/U942zl64_6-api-health-check-best-practices.webp)](https://api7.ai/blog/tips-for-health-check-best-practices)

## [API Health Check Methods and Best Practices](https://api7.ai/blog/tips-for-health-check-best-practices)

[![API Gateway Health Checks: Active and Passive Practices](https://static.api7.ai/uploads/2025/03/21/FX4ibDEU_10-health-check-best-practices.webp)](https://api7.ai/blog/10-best-practices-of-api-gateway-health-checks)

## [API Gateway Health Checks: Active and Passive Practices](https://api7.ai/blog/10-best-practices-of-api-gateway-health-checks)

Table of Contents

- - [About Prometheus](#about-prometheus)
  - [Enabling Prometheus Plugin in Apache APISIX](#enabling-prometheus-plugin-in-apache-apisix)
  - [Configuring Collection Strategy in Prometheus](#configuring-collection-strategy-in-prometheus)
  - [Common Metrics in Apache APISIX](#common-metrics-in-apache-apisix)
  - [Visualization and Alerts](#visualization-and-alerts)
- [Optimization Considerations](#optimization-considerations)
- [Conclusion](#conclusion)

## Related Posts

[![Simplified Log Collection with APISIX's http-logger Plugin](https://static.api7.ai/uploads/2024/04/11/Zod2vE0f_http-logger-cover.png)](https://api7.ai/blog/apisix-http-logger-plugin)

Technology

April 11, 2024

#### [Simplified Log Collection with APISIX's http-logger Plugin](https://api7.ai/blog/apisix-http-logger-plugin)

Learn how to enhance development efficiency with real-time API call log monitoring using the APISIX http-logger plugin.

[Observability](https://api7.ai/tags/observability)

[Monitoring](https://api7.ai/tags/monitoring)

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[![Mastering APISIX Health Checks: Active and Passive Monitoring Strategies](https://static.api7.ai/uploads/2024/01/11/yJqiZUi2_health-check-cover.png)](https://api7.ai/blog/health-check-ensures-high-availability)

Technology

January 11, 2024

#### [Mastering APISIX Health Checks: Active and Passive Monitoring Strategies](https://api7.ai/blog/health-check-ensures-high-availability)

Let's explore how APISIX, an open-source API gateway, employs robust health check mechanisms, actively and passively monitoring nodes.

[Monitoring](https://api7.ai/tags/monitoring)

[APISIX Basics](https://api7.ai/tags/apisix-basics)

[![Configuring Alerts: Key Measures to Elevate API Stability](https://static.api7.ai/uploads/2024/01/04/ExKAUjBR_alerts-cover-en.png)](https://api7.ai/blog/configuring-alerts-for-stable-api)

Technology

January 6, 2024

#### [Configuring Alerts: Key Measures to Elevate API Stability](https://api7.ai/blog/configuring-alerts-for-stable-api)

Discover how to enhance API stability through optimizing alert configuration, ensuring smooth business operations.

[Monitoring](https://api7.ai/tags/monitoring)

[Observability](https://api7.ai/tags/observability)

[APISIX Basics](https://api7.ai/tags/apisix-basics)
