Monitoring APISIX with Prometheus and Grafana


Introduction


Monitoring is crucial for maintaining a healthy API gateway infrastructure. APISIX provides comprehensive monitoring capabilities through integration with Prometheus and Grafana. This guide will show you how to set up monitoring for your APISIX instance and create meaningful dashboards.


Prerequisites

  • APISIX installed and running
  • Prometheus server
  • Grafana installation
  • Basic understanding of metrics and monitoring concepts

1. Enabling Prometheus Metrics in APISIX

First, enable the Prometheus plugin in your APISIX configuration:

{
  "plugins": {
    "prometheus": {
      "export_addr": {
        "ip": "0.0.0.0",
        "port": 9091
      }
    }
  }
}

2. Configuring Prometheus

Add APISIX as a target in your Prometheus configuration:

scrape_configs:
  - job_name: 'apisix'
    static_configs:
      - targets: ['localhost:9091']
    metrics_path: '/metrics'

3. Key Metrics to Monitor

  • apisix_http_status: HTTP status codes distribution
  • apisix_http_latency: Request latency statistics
  • apisix_bandwidth: Network bandwidth usage
  • apisix_etcd_reachable: etcd connectivity status

4. Setting Up Grafana Dashboards

Create a new dashboard in Grafana with these essential panels:

# Request Rate Panel Query
sum(rate(apisix_http_status[1m])) by (status)

# Latency Panel Query
histogram_quantile(0.95, 
  sum(rate(apisix_http_latency_bucket[5m])) by (le))

5. Alerting Configuration

Set up alerts for critical conditions:

# High Error Rate Alert
alert: HighErrorRate
expr: sum(rate(apisix_http_status{status=~"5.."}[5m])) 
      / sum(rate(apisix_http_status[5m])) > 0.1
for: 5m
labels:
  severity: critical

6. Best Practices

  • Monitor both infrastructure and business metrics
  • Set up appropriate retention periods for metrics
  • Use labels effectively for better metric organization
  • Implement proper alerting thresholds
  • Regular dashboard maintenance and updates

Conclusion

Proper monitoring is essential for maintaining a reliable APISIX deployment. By following this guide, you'll have comprehensive visibility into your API gateway's performance and health.


View APISIX Documentation on GitHub


Read Next