envoy-guide
Module 4 · Observability·14 min·intermediate

Prometheus metrics

Scrape /stats/prometheus and chart per-cluster behavior.

Envoy's metrics, for free

Every Envoy emits a long list of counters, gauges, and histograms by default — without you adding any config beyond the admin interface. They're exposed at:

Text
http://localhost:9901/stats              # plain text
http://localhost:9901/stats/prometheus   # Prometheus scrape format

Per-cluster, per-listener, per-virtual-host stats are all there. Most of the dashboards you'll ever want for an Envoy fleet come from a handful of metric families.

The metrics you'll actually use

MetricWhat it measures
envoy_cluster_upstream_rq_totalRequests sent to a cluster (rate)
envoy_cluster_upstream_rq_xx{response_code_class="2"}2xx broken out (also 4, 5)
envoy_cluster_upstream_rq_time_bucketRequest latency histogram (→ p50/p95/p99)
envoy_cluster_upstream_cx_activeOpen connections to a cluster
envoy_cluster_upstream_rq_retryHow often retries fire
envoy_cluster_upstream_rq_pending_overflowCircuit breakers tripping
envoy_cluster_outlier_detection_ejections_activeHow many endpoints are currently ejected
envoy_listener_downstream_cx_totalInbound connections per listener
envoy_server_state0 = LIVE, 1 = DRAINING, 2 = PRE_INITIALIZING, 3 = INITIALIZING

All envoy_cluster_* metrics come pre-tagged with the cluster name as a label. That's what makes per-cluster dashboards trivial.

Scraping with Prometheus

A minimal prometheus.yml:

YAML
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: envoy
    metrics_path: /stats/prometheus
    static_configs:
      - targets: ["envoy:9901"]

If you also want only a subset of stats (Envoy emits a lot), narrow them at the source with a stats_config in envoy.yaml:

YAML
stats_config:
  stats_matcher:
    inclusion_list:
      patterns:
      - prefix: "cluster."
      - prefix: "http."
      - prefix: "listener."
      - prefix: "server."

That alone can cut your scrape size by 70%.

Hands-on: end-to-end Prometheus + Grafana

Hands-on · Stand up the full stack with docker-compose

Create a folder with three files: envoy.yaml (your Lesson 5 hello-world is fine), prometheus.yml (above), and compose.yaml:

YAML
services:
  envoy:
    image: envoyproxy/envoy:v1.31-latest
    volumes: [ "./envoy.yaml:/etc/envoy/envoy.yaml" ]
    ports: [ "10000:10000", "9901:9901" ]
  prometheus:
    image: prom/prometheus:latest
    volumes: [ "./prometheus.yml:/etc/prometheus/prometheus.yml" ]
    ports: [ "9090:9090" ]
  grafana:
    image: grafana/grafana:latest
    environment:
      GF_AUTH_ANONYMOUS_ENABLED: "true"
      GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
    ports: [ "3000:3000" ]

Bring it up:

Shell
docker compose up -d

Generate some load:

Shell
while true; do curl -s -o /dev/null localhost:10000/get; sleep 0.1; done

In Grafana (localhost:3000), add a Prometheus data source at http://prometheus:9090. Then chart:

PromQL
rate(envoy_cluster_upstream_rq_total[1m])

You should see request rate per cluster. Add a second panel for latency:

PromQL
histogram_quantile(0.95,
  sum by (le, envoy_cluster_name) (
    rate(envoy_cluster_upstream_rq_time_bucket[5m])
  )
)

That's a real p95-by-cluster panel. Tear it down with docker compose down.

There is a community dashboard

You don't have to build dashboards from scratch — search Grafana Dashboards for "Envoy Proxy"; ID 11021 (or similar) will give you a pre-built panel set covering RPS, latency, retry rate, and circuit-breaker overflows.

Real-world example · A platform team operating 200 Envoy sidecars
Problem
An on-call engineer gets paged: "checkout latency is up." Without per-service breakdown, they have to log into ten dashboards to find the bad service.
Envoy solution
Every Envoy sidecar emits the same set of envoy_cluster_* metrics, tagged with the cluster name (= the upstream service). One Grafana panel — histogram_quantile(0.95, sum by (cluster) (...)) — shows p95 broken down by every upstream service in the mesh, sorted descending. The bad service jumps to the top. Triage time: under a minute.

Up next

Logs tell you about individual requests. Metrics tell you about aggregates. Traces tell you about the journey of one request across many services. That's Lesson 14.

Quick check

Which metric tracks 5xx responses Envoy received from a cluster's upstream?

Practical task
Finish the quick check and tick off the task to unlock.
Quick checkTasks 0/3