Skip to main content

Version: 3.10.x

a7-plugin-prometheus

Overview

The prometheus plugin exposes API7 EE metrics in Prometheus text format. It tracks HTTP status codes, request latency, bandwidth, upstream health, and system status. API7 EE includes a built-in metrics endpoint that can be scraped by Prometheus; Grafana is used for visualization.

When to Use

  • Monitor request rates, error rates, and latency per route/service/consumer
  • Track upstream health check status
  • Observe system-wide performance and resource usage
  • Build dashboards and alerts with Prometheus + Grafana

Plugin Configuration Reference (Route/Service/Global Rule)

FieldTypeRequiredDefaultDescription
prefer_namebooleanNofalseUse route/service name instead of ID in metric labels

The plugin has minimal per-route config. Most configuration is managed via API7 EE gateway group settings.

Metrics Exported

Core Metrics

MetricTypeDescription
apisix_http_statuscounterHTTP status codes per route/service/consumer
apisix_http_latencyhistogramRequest latency in ms (types: request, upstream, apisix)
apisix_bandwidthcounterBandwidth in bytes (types: ingress, egress)
apisix_http_requests_totalgaugeTotal HTTP requests received
apisix_nginx_http_current_connectionsgaugeCurrent connections by state
apisix_upstream_statusgaugeUpstream health (1=healthy, 0=unhealthy)
apisix_node_infogaugeAPI7 EE node hostname and version
apisix_shared_dict_capacity_bytesgaugeShared memory capacity
apisix_shared_dict_free_space_bytesgaugeShared memory free space

API7 EE Built-in Metrics Endpoint

API7 Enterprise Edition provides a built-in metrics endpoint. By default, this is available at /apisix/prometheus/metrics on the configured prometheus port (usually 9091 or exposed via the data plane port 9080).

Step-by-Step: Enable Prometheus Metrics

1. Enable on a route

Enable metrics for gateway group default:

a7 route create --gateway-group default -f - <<'EOF'
{
"id": "my-api",
"uri": "/api/*",
"plugins": {
"prometheus": {
"prefer_name": true
}
},
"upstream": {
"type": "roundrobin",
"nodes": [{"host": "backend", "port": 8080, "weight": 1}]
}
}
EOF

2. Enable globally (all routes in a group)

Use a Global Rule to enable metrics for all routes in the prod group:

a7 global_rule create --gateway-group prod -f - <<'EOF'
{
"id": "prometheus-global",
"plugins": {
"prometheus": {}
}
}
EOF

3. Access metrics

Default endpoint: http://<gateway-host>:9091/apisix/prometheus/metrics

4. Configure Prometheus scrape

# prometheus.yml
scrape_configs:
- job_name: api7-ee
scrape_interval: 15s
static_configs:
- targets: ['gateway-host:9091']

Common Patterns

Custom metric prefix and export port

These are typically configured in the API7 EE Dashboard or via gateway group configuration.

Extra labels on metrics

Extra labels can be added to capture additional context like upstream addresses or specific header values.

Custom histogram buckets

Default buckets for latency are: 1, 2, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000, 2000, 5000, 10000, 30000, 60000 ms.

Troubleshooting

SymptomCauseFix
No metrics at endpointPlugin not enabledAdd prometheus: {} to route or global_rules
Metrics port unreachableExport server not enabledCheck API7 EE gateway group settings
Missing route labelsprefer_name: false and route has no nameSet prefer_name: true and name your routes
High cardinalityToo many extra labelsReduce extra_labels to avoid metric explosion
Config not appliedWrong gateway group specifiedEnsure --gateway-group matches the desired cluster

Config Sync Example

version: "1"
gateway_group: default
global_rules:
- id: prometheus-global
plugins:
prometheus:
prefer_name: true
routes:
- id: my-api
uri: /api/*
plugins:
prometheus: {}
upstream:
type: roundrobin
nodes:
- host: backend
port: 8080
weight: 1

This page is generated from a7-plugin-prometheus/SKILL.md in the api7/a7 repository. Browse all skills on the AI Agent Skills page.

API7.ai Logo

The digital world is connected by APIs,
API7.ai exists to make APIs more efficient, reliable, and secure.

Sign up for API7 newsletter

Product

API7 Gateway

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

Copyright © APISEVEN PTE. LTD 2019 – 2026. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the Apache Software Foundation