Monitoring guide
Kafka monitoring: consumer lag and broker health
For most teams, the question about Kafka is simple: are consumers keeping up? Consumer lag answers it; broker health explains it when they are not.
4 min read13 sectionsUpdated
On this page
| Metric | Meaning | Worry when |
|---|---|---|
| Consumer lag (messages or time) | How far consumers are behind | Growing steadily, or above your freshness target |
| Under-replicated partitions | Replicas not in sync | Above 0 |
| Offline partitions / active controller | Cluster availability | Offline > 0; controller count ≠ 1 |
| Request latency (produce, fetch) | Broker responsiveness | p99 rising |
| Broker disk used | Retention vs capacity | Above 80% |
| Producer error / retry rate | Failed sends | Any sustained increase |
Why consumers fall behind
- A slow dependency inside the consumer (database, API) limits throughput; traces show it.
- Too few partitions for the number of consumers you need; one partition is consumed by at most one consumer per group.
- Rebalances triggered by consumers taking longer than
max.poll.interval.ms. - A poison message that fails and retries forever.
receivers:
kafkametrics:
brokers: [kafka:9092]
protocol_version: 2.0.0
scrapers: [brokers, topics, consumers]
collection_interval: 60s
exporters:
otlphttp/vitalrix:
encoding: json
metrics_endpoint: ${env:VITALRIX_API}/api/v1/metrics/otlp/v1/metrics
headers: { x-api-key: ${env:VITALRIX_KEY} }
service:
pipelines:
metrics: { receivers: [kafkametrics], exporters: [otlphttp/vitalrix] }Tracing through Kafka
OpenTelemetry instrumentation for Kafka clients (Java agent, kafkajs and others) injects trace context into message headers, so a consumer's processing appears in the same trace as the request that produced the message. See context propagation.
Kafka monitoring with VitalRix
Collector metrics arrive over OTLP and can be charted on dashboards and used in alert rules. A TCP check confirms Kafka accepts connections from the network your app uses, and APM traces show which requests wait on Kafka and for how long, from the client spans your instrumented services create. Alert on consumer lag from the Collector metrics, and use heartbeat checks for consumers that should process at least one batch every few minutes.
Alerts to start with
- Consumer lag (time) above your freshness target for 10 minutes, per group.
- Under-replicated partitions above 0 for 5 minutes.
- Offline partitions above 0, immediately.
- Broker disk above 80%.
- A heartbeat from each critical consumer that processes at least one batch every few minutes.
The Kafka metrics that matter
Broker metrics come over JMX (most teams export them with the Prometheus JMX exporter or an OpenTelemetry receiver); consumer lag comes from the consumer group offsets.
| Metric | What it tells you | Starting alert |
|---|---|---|
| Consumer lag per group and partition | Messages produced but not yet consumed | Growing for 10 minutes, or above what your SLA allows |
| UnderReplicatedPartitions | Partitions with fewer in-sync replicas than configured | Above zero for 5 minutes |
| OfflinePartitionsCount | Partitions with no leader | Above zero: data is unavailable |
| ActiveControllerCount | Exactly one controller in the cluster | Anything other than 1 across the cluster |
| ISR shrink and expand rate | Replicas falling out of sync | Frequent shrinks |
| Request latency (produce, fetch) | Total time per request type | p99 rising against the usual |
| Disk use per broker | Log directory | Above 80% |
# lag per partition for one consumer group
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group orders-service
# partitions that are under-replicated right now
kafka-topics.sh --bootstrap-server localhost:9092 --describe --under-replicated-partitionsWhat the incidents look like
- Lag grows on one partition only: a hot key sends most messages to one partition, so one consumer falls behind while the others idle.
- Lag grows everywhere after a deploy: consumers got slower, crash and rebalance in a loop, or a downstream database is slow.
- Under-replicated partitions when a broker is overloaded, its disk is slow or it is down. With acks=all and min.insync.replicas, producers start failing when too few replicas remain.
- Disk fills because retention is set by time and traffic grew. Alert on disk, and set retention by size on high-volume topics.
Lag says that consumers are behind, not why. Traces across producer and consumer show whether the time goes into the queue or into processing; see monitoring background jobs and queues.
Is lag in messages or time better?
Time lag (how old the oldest unprocessed message is) maps directly to user impact. Message lag is easier to get; convert it using the produce rate.
How many partitions do I need?
At least as many as the consumers you want running in parallel, with room to grow. Changing partition counts later affects key ordering.
Related reading
- Kafka consumer lag: how to measure and reduce it: Measure and reduce Kafka consumer lag: read kafka-consumer-groups output, spot rebalances and slow processing, and decide when more partitions will help.
- How to monitor Fly.io: How to monitor apps on Fly.io: multi-region uptime checks, machine health, the built-in Prometheus metrics, Postgres clusters, OpenTelemetry traces and alerts.
- MongoDB monitoring: metrics that matter: Monitor MongoDB: operation rates and latency, slow queries from the profiler, WiredTiger cache, connections, replication lag and oplog window.
- MySQL monitoring: key metrics and alerts: Monitor MySQL: connections and threads, query throughput, slow queries, InnoDB buffer pool, replication lag and disk, with the SQL for each check.
- The three pillars of observability: Logs, metrics and traces compared: what each pillar of observability is good at, what it costs, and how to link them so one alert leads to the cause.
- AWS monitoring with CloudWatch metrics: Monitor AWS workloads: which CloudWatch metrics matter for EC2, RDS, ELB and SQS, the IAM permissions to read them and the alerts to set.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.