Skip to content

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

Key points

  • Consumer lag per group and partition is the main signal.
  • Under-replicated partitions mean data is at risk.
  • Disk usage on brokers grows with retention.
  • Trace producers and consumers to follow a message end to end.

Checking consumer lag

bash
kafka-consumer-groups.sh --bootstrap-server kafka:9092 --describe --group orders-consumer
# GROUP            TOPIC   PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG
# orders-consumer  orders  0          1849201         1849214         13
# orders-consumer  orders  1          1838877         1912880         74003   <- falling behind

What to watch

MetricMeaningWorry when
Consumer lag (messages or time)How far consumers are behindGrowing steadily, or above your freshness target
Under-replicated partitionsReplicas not in syncAbove 0
Offline partitions / active controllerCluster availabilityOffline > 0; controller count ≠ 1
Request latency (produce, fetch)Broker responsivenessp99 rising
Broker disk usedRetention vs capacityAbove 80%
Producer error / retry rateFailed sendsAny 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.

Collecting metrics

otel-collector.yamlyaml
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.

MetricWhat it tells youStarting alert
Consumer lag per group and partitionMessages produced but not yet consumedGrowing for 10 minutes, or above what your SLA allows
UnderReplicatedPartitionsPartitions with fewer in-sync replicas than configuredAbove zero for 5 minutes
OfflinePartitionsCountPartitions with no leaderAbove zero: data is unavailable
ActiveControllerCountExactly one controller in the clusterAnything other than 1 across the cluster
ISR shrink and expand rateReplicas falling out of syncFrequent shrinks
Request latency (produce, fetch)Total time per request typep99 rising against the usual
Disk use per brokerLog directoryAbove 80%
bash
# 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-partitions

What 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.

Frequently asked questions

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.

  • 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.