# Monitor APISIX Metrics with Prometheus

Prometheus is a popular systems monitoring and alerting toolkit. It collects and stores multi-dimensional time series data like metrics with key-value paired labels.

APISIX offers the capability to expose a significant number of metrics to Prometheus [with low latency](https://api7.ai/blog/1s-to-10ms-reducing-prometheus-delay-in-api-gateway), allowing for continuous monitoring and diagnostics.

This guide will show you how to enable the [`prometheus`](https://docs.api7.ai/hub/prometheus.md) plugin to integrate with Prometheus and Grafana services, where APISIX HTTP metrics are collected and visualized.

<br />

![APISIX Prometheus Grafana flow diagram](https://static.api7.ai/uploads/2023/05/16/5Z5bIUwF_grafana-prometheus.jpg)

<br />

## Prerequisite(s)[​](#prerequisites "Direct link to Prerequisite(s)")

* Install [Docker](https://docs.docker.com/get-docker/).
* Install [cURL](https://curl.se/) to send requests to the services for validation.
* Follow the [Getting Started tutorial](https://docs.api7.ai/apisix/getting-started.md) to start a new APISIX instance in Docker.
* If you use the Admin API examples and authentication is enabled, export an admin-role key as `ADMIN_API_KEY`. Configure the key under `deployment.admin.admin_key`. The Docker quickstart disables authentication for local evaluation; keep it enabled in production.

## Enable Prometheus Plugin[​](#enable-prometheus-plugin "Direct link to Enable Prometheus Plugin")

Enable the `prometheus` plugin globally. Alternatively, you can enable the plugin on a route.

* Admin API
* ADC

```
curl "http://127.0.0.1:9180/apisix/admin/global_rules/prometheus" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "plugins": {

      "prometheus": {}

    }

  }'
```

APISIX gathers internal runtime metrics and exposes them through port `9091` and path `/apisix/prometheus/metrics` by default. The port and the path can be [customized in the configuration file](https://docs.api7.ai/hub/prometheus/configuration.md#static-configurations).

ADC exports global rules as one map keyed by plugin name. That export does not keep the original rule ID or which plugins shared a rule. If more than one rule configures the same plugin, the export keeps only one configuration. Use the Admin API tab in this section when you need to keep the original rule ID or grouping.

Export the current global rules:

```
adc dump -o adc-global-rules.yaml \

  --include-resource-type global_rule
```

caution

ADC dumps can contain decrypted sensitive fields returned by the Admin API. Restrict access to exported files and delete them after completing the change.

Edit the exported file to add the Prometheus plugin while preserving every other plugin entry:

adc-global-rules.yaml (global\_rules excerpt)

```
global_rules:

  # Keep every other global plugin entry from the exported file.

  prometheus: {}
```

Preview the global rules and confirm that the diff contains no unrelated plugin changes or deletions:

```
adc diff -f adc-global-rules.yaml \

  --include-resource-type global_rule
```

Synchronize the reviewed global rules:

```
adc sync -f adc-global-rules.yaml \

  --include-resource-type global_rule
```

APISIX gathers internal runtime metrics and exposes them through port `9091` and path `/apisix/prometheus/metrics` by default. The port and the path can be [customized in the configuration file](https://docs.api7.ai/hub/prometheus/configuration.md#static-configurations).

Send a request to the route `/apisix/prometheus/metrics` to fetch metrics from APISIX:

```
curl "http://127.0.0.1:9091/apisix/prometheus/metrics"
```

You should see a list of metrics similar to the following:

```
# HELP apisix_etcd_modify_indexes Etcd modify index for APISIX keys

# TYPE apisix_etcd_modify_indexes gauge

apisix_etcd_modify_indexes{key="consumers"} 0

apisix_etcd_modify_indexes{key="global_rules"} 0

apisix_etcd_modify_indexes{key="max_modify_index"} 16

apisix_etcd_modify_indexes{key="prev_index"} 15

apisix_etcd_modify_indexes{key="protos"} 0

apisix_etcd_modify_indexes{key="routes"} 16

apisix_etcd_modify_indexes{key="services"} 0

apisix_etcd_modify_indexes{key="ssls"} 0

apisix_etcd_modify_indexes{key="stream_routes"} 0

apisix_etcd_modify_indexes{key="upstreams"} 0

apisix_etcd_modify_indexes{key="x_etcd_index"} 16

# HELP apisix_etcd_reachable Config server etcd reachable from APISIX, 0 is unreachable

# TYPE apisix_etcd_reachable gauge

apisix_etcd_reachable 1

...

# HELP apisix_http_status HTTP status codes per service in APISIX

# TYPE apisix_http_status counter

...
```

## Configure Prometheus[​](#configure-prometheus "Direct link to Configure Prometheus")

In Prometheus, targets are the endpoints that Prometheus scrapes for metrics. You can configure the APISIX metrics endpoint as a target in Prometheus to collect metrics from it.

Create a configuration file `prometheus.yml`:

```
cat > prometheus.yml <<'EOF'

global:

  scrape_interval: 15s



scrape_configs:

  - job_name: apisix

    metrics_path: /apisix/prometheus/metrics

    static_configs:

      - targets:

          - apisix-quickstart:9091

EOF
```

Create a data volume and start Prometheus. Port `9092` on the host maps to the Prometheus web interface on port `9090` in the container:

```
docker volume create apisix-quickstart-prometheus-data



docker run -d --name apisix-quickstart-prometheus \

  --network apisix-quickstart-net \

  -p 9092:9090 \

  -v "$(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml:ro" \

  -v apisix-quickstart-prometheus-data:/prometheus \

  prom/prometheus:v3.7.3
```

Open the Prometheus [targets page](http://127.0.0.1:9092/targets). The `apisix` target should have the `UP` state.

![Prometheus targets page showing the APISIX target in the UP state](https://static.api7.ai/uploads/2026/07/24/qkNnSHjd_prometheus-apisix-target.png)

## Configure Grafana[​](#configure-grafana "Direct link to Configure Grafana")

Grafana can visualize metrics stored in Prometheus.

Create a data volume and start Grafana on the same Docker network:

```
docker volume create apisix-quickstart-grafana-data



docker run -d --name apisix-quickstart-grafana \

  --network apisix-quickstart-net \

  -p 3000:3000 \

  -v apisix-quickstart-grafana-data:/var/lib/grafana \

  grafana/grafana:13.1.0
```

Open [Grafana](http://127.0.0.1:3000), sign in with the default username and password `admin`, and change the password when prompted.

Go to **Connections > Data sources**, add a Prometheus data source, and set its URL to `http://apisix-quickstart-prometheus:9090`. This URL uses the Prometheus container name and container port because Grafana makes the request from inside the Docker network. Select **Save & test** and verify that Grafana can query Prometheus.

![Grafana Prometheus data source configured with the Prometheus container URL](https://static.api7.ai/uploads/2026/07/24/y8bOECnE_grafana-prometheus-data-source.png)

Generate gateway traffic and wait for Prometheus to complete a scrape:

```
for i in {1..100}; do

  curl -sS "http://127.0.0.1:9080/ip" > /dev/null

done



sleep 15
```

Download the dashboard maintained in the Apache APISIX source tree for this version:

```
curl -fL "https://raw.githubusercontent.com/apache/apisix/3.21.0/docs/assets/other/json/apisix-grafana-dashboard.json" \

  -o apisix-grafana-dashboard.json
```

note

The Grafana catalog page for [dashboard 11719](https://grafana.com/grafana/dashboards/11719-apache-apisix/) lists compatibility with APISIX 2.10.x and depends on legacy Grafana panels. Use the versioned dashboard JSON above for the metrics exposed in this guide.

In Grafana, go to **Dashboards > New > Import**, upload `apisix-grafana-dashboard.json`, select the Prometheus data source, and select **Import**.

![Grafana dashboard import page with the Apache APISIX dashboard JSON loaded](https://static.api7.ai/uploads/2026/07/24/GraNfl76_grafana-import-dashboard.png)

The dashboard should populate with the requests generated above and show APISIX connection, request, latency, bandwidth, etcd, and shared dictionary metrics.

If you already scrape `apisix_llm_latency`, update PromQL, recording rules, and Grafana panels that omit the `type` label. That histogram now distinguishes `type="total"` (full response latency) from `type="ttft"` (time to first token on streaming requests). A selector without `type` matches both. Use `type="total"` when you need the previous total-latency meaning:

```
histogram_quantile(0.99, sum by (le, route_id) (rate(apisix_llm_latency_bucket{type="total"}[5m])))
```

Each streaming request records one `total` observation and one `ttft` observation, so sample counts and time-series cardinality increase for streaming traffic.

![Apache APISIX Grafana dashboard populated with live gateway metrics](https://static.api7.ai/uploads/2026/07/24/bU62llSy_grafana-apisix-dashboard.png)

## Reduce Metric Cardinality[​](#reduce-metric-cardinality "Direct link to Reduce Metric Cardinality")

High-cardinality labels, such as an upstream node address that changes frequently, can create many time series. Configure the `prometheus` plugin metadata to replace selected label values with an empty string while keeping the labels in the metric schema:

```
curl "http://127.0.0.1:9180/apisix/admin/plugin_metadata/prometheus" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "disabled_labels": {

      "http_status": ["node"],

      "http_latency": ["node"]

    }

  }'
```

Generate traffic and fetch the metrics endpoint again. The affected series should retain the `node` label with an empty value:

```
apisix_http_status{code="200",route="1",matched_uri="/ip",matched_host="",service="",consumer="",node="",request_type="traditional_http",request_llm_model="",llm_model="",response_source="upstream"} 100
```

APISIX rejects attempts to disable structural labels that distinguish different measurements, including `code` for HTTP status and `type` for latency and bandwidth. See the [`prometheus` plugin metadata reference](https://docs.api7.ai/hub/prometheus/configuration.md#plugin-metadata) for the labels supported by each metric.

## Monitor TCP and UDP Traffic[​](#monitor-tcp-and-udp-traffic "Direct link to Monitor TCP and UDP Traffic")

Enable the stream proxy and add `prometheus` to the existing `stream_plugins` list. The following minimal list is sufficient for this example; preserve any other stream plugins your deployment uses:

config.yaml

```
apisix:

  proxy_mode: http&stream

  stream_proxy:

    tcp:

      - 9100



stream_plugins:

  - prometheus
```

Reload APISIX, then create a stream route:

```
curl "http://127.0.0.1:9180/apisix/admin/stream_routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "id": "prometheus-stream-route",

    "plugins": {

      "prometheus": {}

    },

    "upstream": {

      "type": "roundrobin",

      "nodes": {

        "httpbin.org:80": 1

      }

    }

  }'
```

Send traffic through the stream listener and scrape the metrics endpoint:

```
curl -i "http://127.0.0.1:9100"

curl "http://127.0.0.1:9091/apisix/prometheus/metrics" | grep apisix_stream
```

The output should include the connection total, active sessions, termination status, and bandwidth counters:

```
apisix_stream_connection_total{route="prometheus-stream-route",service="",service_id=""} 1

apisix_stream_active_connections{listen_addr="0.0.0.0:9100",service="",service_id=""} 0

apisix_stream_status{code="200",listen_addr="0.0.0.0:9100",service="",service_id="",node="54.237.103.220:80"} 1

apisix_stream_bandwidth{listen_addr="0.0.0.0:9100",service="",service_id="",type="ingress",side="downstream"} 78
```

The stream route in this example does not belong to a service, so `service` and `service_id` are empty. The upstream address and byte count depend on the request. The active-session value is `0` after the request closes. The active-session and bandwidth metrics use the shared memory size configured by `nginx_config.stream.metrics_zone_size`, which defaults to `1m`.

The service labels change the identity of existing stream series. To retain an aggregate that ignores the service dimensions, sum without the new labels:

```
sum without (service, service_id) (apisix_stream_connection_total)
```

## Separate WebSocket Sessions from HTTP Latency[​](#separate-websocket-sessions-from-http-latency "Direct link to Separate WebSocket Sessions from HTTP Latency")

Successful WebSocket upgrades use the `request_type="websocket"` label in the HTTP status, latency, and bandwidth metrics. They do not appear under `traditional_http`. Request latency includes the upgraded connection's lifetime rather than a short HTTP round trip.

For example, this PromQL query calculates the 95th percentile of ordinary HTTP request latency by route:

```
histogram_quantile(

  0.95,

  sum by (le, route) (

    rate(apisix_http_latency_bucket{type="request",request_type="traditional_http"}[5m])

  )

)
```

To include HTTP and AI requests but exclude WebSocket sessions, replace the request-type matcher with `request_type!="websocket"`. Review dashboard, alert, and recording-rule selectors when upgrading, including queries that previously counted WebSocket upgrades as ordinary HTTP traffic.

Close a test WebSocket session before checking these per-request metrics because they are recorded after the session ends. See the [Prometheus plugin reference](https://docs.api7.ai/hub/prometheus.md#labels-for-apisix_http_latency) for the complete latency labels.

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have now learned how to monitor APISIX metrics with Prometheus and visualize them in Grafana. See the [`prometheus`](https://docs.api7.ai/hub/prometheus.md) plugin documentation for more configuration options.
