1. Real-World Problem: A Sluggish System with an Unknown Bottleneck
Around 9 AM on a Monday, the operations team was hit with dozens of complaint tickets: “The app keeps spinning, and checkout fails with a connection error.” Checking the 3-node Kong API Gateway cluster, CPU and RAM were idling comfortably at 25–30%. Yet, the request success rate plummeted from 99.9% to under 80%. Users were repeatedly encountering HTTP 504 Gateway Timeout and 502 Bad Gateway errors.
Without a centralized metrics system, you would have to SSH into each server and painfully grep through gigabytes of Nginx access logs. This manual approach burns hours while still leaving you guessing which route is bottlenecked or which backend has crashed, putting your firefighting efforts in a completely reactive position.
2. Root Cause Analysis: The Blind Spot Between API Gateway and Upstream Services
In a microservices architecture, Kong sits at the front of the funnel to handle incoming traffic and route it to downstream services such as Auth, Order, or Payment. When bottlenecks or logic errors occur, operations teams often face three critical blind spots:
- Conflated Latency Metrics (Kong Latency vs. Upstream Latency): Total response time consists of Kong’s internal processing time (running plugins, verifying JWTs, rate limiting) plus upstream processing time. Kong typically adds only 2–5ms. If total latency spikes to 3000ms without isolating these two metrics, it’s impossible to tell whether Kong is overloaded or the Order Service’s database is suffering from locked tables.
- Silent Spikes in HTTP Error Codes: Surges in 4xx and 5xx errors on a specific endpoint easily get lost in tens of thousands of requests per second, especially when host CPU usage looks completely healthy.
- Lack of Per-Service Throughput Visibility: Without accurately tracking Requests Per Second (RPS) for each service, configuring autoscaling for your backends comes down to pure guesswork.
3. Three Common Approaches to Monitoring Kong
To track the health of an API Gateway cluster, infrastructure teams typically consider three solutions:
- Approach 1: Centralized Log Aggregation and Analysis (Filebeat + ELK/Loki): Shipping access logs to a centralized logging cluster to parse the
upstream_response_timeandstatusfields. While this provides detailed request traces, it consumes significant disk storage and often introduces a 30-second to several-minute delay, making it too slow for real-time alerting. - Approach 2: Installing APM Agents (Datadog, Elastic APM, New Relic): Running deep in-process monitoring agents. This approach provides fine-grained profiling down to individual function calls, but licensing costs are high and agents can introduce conflicts when hooked directly into Kong’s OpenResty core.
- Approach 3: Using Kong’s Native Prometheus Plugin with Grafana: Enabling Kong’s built-in plugin to expose standard OpenMetrics via an internal endpoint. Prometheus then scrapes the metrics at regular intervals, and Grafana handles visualization.
4. The Optimal Solution: Setting Up Prometheus and Grafana
Leveraging Kong’s official prometheus plugin is the standard best practice for production environments. It introduces minimal resource overhead, avoids throughput degradation on the gateway, and provides clear separation of latency metrics.
Step 1: Enable the Prometheus Plugin on Kong Gateway
You can enable the plugin cluster-wide (globally) with a single Kong Admin API call:
curl -i -X POST http://localhost:8001/plugins/ \
--data "name=prometheus" \
--data "config.status_code_metrics=true" \
--data "config.latency_metrics=true" \
--data "config.bandwidth_metrics=true" \
--data "config.upstream_health_metrics=true"
Once enabled, verify Kong’s metrics endpoint (defaulting to Admin port 8001 or status port 8100):
curl http://localhost:8001/metrics
Kong will return standard metric strings such as kong_http_status (or kong_http_requests_total), kong_latency_bucket, and kong_bandwidth.
Step 2: Configure Prometheus to Scrape Kong Metrics
Add a new job to your prometheus.yml file with a 10-second scrape interval:
scrape_configs:
- job_name: 'kong-gateway'
scrape_interval: 10s
metrics_path: /metrics
static_configs:
- targets: ['192.168.1.50:8001']
labels:
env: 'production'
cluster: 'kong-edge'
Apply the new configuration without restarting the service:
curl -X POST http://localhost:9090/-/reload
Step 3: Write Key PromQL Queries
Here are three core PromQL queries to give you complete visibility into system health:
1. Measure Throughput (RPS) Broken Down by Service:
sum(rate(kong_http_status[1m])) by (service)
2. Measure P95 Upstream Latency:
histogram_quantile(0.95, sum(rate(kong_latency_bucket{type="upstream"}[5m])) by (le, service))
This metric reveals the response time for 95% of requests sent to the backend. If this number jumps to 2500ms while type="kong" remains at 3ms, you have clear evidence to ask the backend team to optimize queries or scale the service immediately.
3. Measure 5xx Error Rate Against Total Traffic:
sum(rate(kong_http_status{code=~"5.."}[1m])) by (service, code) / sum(rate(kong_http_status[1m])) by (service) * 100
Step 4: Build Visualizations in Grafana
Instead of manually building individual panels, you can simply import a prebuilt community dashboard designed specifically for Kong (Dashboard ID: 7424):
- Log in to Grafana and navigate to Dashboards > Import.
- Enter ID
7424into the field and click Load. - Set the data source to your Prometheus instance and click Import.
Instantly, you will have a comprehensive dashboard featuring RPS graphs, P90/P95/P99 latency percentiles, and color-coded HTTP status code charts. When a microservice runs into issues, its specific graph will spike dramatically, allowing the team to pinpoint the exact bottleneck in 30 seconds rather than spending hours digging in the dark.

