Lesson 15 of 17 · Operating Kafka
Monitoring and troubleshooting
What to watch on a Kafka cluster and how to fix what breaks. The broker metrics that matter (under-replicated, under-min-ISR and offline partitions, the active controller, request handler idle time, request latency, disk), client metrics and consumer lag, how to collect them with the JMX exporter and Kafka Exporter, a dashboard and alert set, and a field guide to the common incidents with the commands to diagnose each.
What to watch
Kafka exposes thousands of metrics through JMX. A few matter most.
Cluster and partition health
| Metric (JMX name, short) | Healthy | Meaning when not |
|---|---|---|
ReplicaManager UnderReplicatedPartitions |
0 | A replica is behind or a broker is down |
ReplicaManager UnderMinIsrPartitionCount |
0 | acks=all writes are being refused |
KafkaController OfflinePartitionsCount |
0 | No leader: data unavailable |
KafkaController ActiveControllerCount |
Sum across nodes = 1 | No controller, or a split |
ReplicaManager IsrShrinksPerSec / IsrExpandsPerSec |
Near 0 | Replicas flapping in and out of sync |
ReplicaManager PartitionCount, LeaderCount per broker |
Even | Imbalanced load |
Broker load
| Metric | Watch for |
|---|---|
KafkaRequestHandlerPool RequestHandlerAvgIdlePercent |
Below 30%: request threads saturated |
SocketServer NetworkProcessorAvgIdlePercent |
Below 30%: network threads saturated |
RequestMetrics TotalTimeMs (Produce, FetchConsumer, FetchFollower) p99 |
Rising latency; break down by RequestQueue, Local, RemoteTime |
BrokerTopicMetrics BytesInPerSec / BytesOutPerSec |
Throughput per broker and topic |
| Disk used and disk I/O per broker | Full disks stop brokers |
| JVM GC pauses, heap | Long pauses cause ISR shrinks |
Clients
- Consumer lag per group and partition, in records and in time.
- Producer:
record-error-rate,request-latency-avg,produce-throttle-time-avg(quotas),buffer-available-bytes. - Consumer:
records-lag-max, rebalance rate,fetch-throttle-time-avg.
Monitoring Kafka is like being the head of a team of lorry drivers. Under-replicated partitions are lorries driving without their spare driver: still moving, but one illness away from a stop. Offline partitions are lorries parked with no driver at all. Consumer lag is the pile of parcels waiting at the depot. Disk is how full the warehouse is: when it's full, nothing more comes in.
Collecting the metrics
- Prometheus JMX exporter as a Java agent on each broker turns JMX into Prometheus metrics (Strimzi:
metricsConfigin theKafkaresource; managed services publish to CloudWatch, Azure Monitor or Prometheus endpoints). - Kafka Exporter (or Burrow, or your platform's lag exporter) for consumer group lag from outside the clients.
- Client metrics from the applications' own Prometheus or OpenTelemetry exporters.
- Broker logs (
server.log, controller logs, authorizer log) into your log platform.
A starter alert set, in Prometheus terms (names depend on your exporter configuration):
groups:
- name: kafka
rules:
- alert: KafkaOfflinePartitions
expr: sum(kafka_controller_kafkacontroller_offlinepartitionscount) > 0
for: 1m
labels: { severity: page }
- alert: KafkaUnderMinIsr
expr: sum(kafka_server_replicamanager_underminisrpartitioncount) > 0
for: 1m
labels: { severity: page }
- alert: KafkaUnderReplicated
expr: sum(kafka_server_replicamanager_underreplicatedpartitions) > 0
for: 10m
labels: { severity: ticket }
- alert: KafkaConsumerLagHigh
expr: sum by (consumergroup) (kafka_consumergroup_lag) > 100000
for: 15m
labels: { severity: ticket }
Field guide: common incidents
1. Consumer lag keeps growing
$ kafka-consumer-groups.sh --bootstrap-server b:9092 --describe --group billing
| Lag pattern | Cause | Fix |
|---|---|---|
| All partitions | Consumers too slow, or a traffic spike | Scale consumers (≤ partitions), speed up processing, batch downstream writes |
| One partition | Hot key, or a poison message | Check that partition's consumer logs; DLQ the bad record; fix key design |
| Lag plus frequent member changes | Rebalance storm: processing exceeds max.poll.interval.ms |
Lower max.poll.records, speed up processing, cooperative or KIP-848 protocol, static membership |
| No members | Consumers crashed or are failing auth | Check deployments, ACLs on topic and group |
2. Producers get NOT_ENOUGH_REPLICAS or timeouts
ISR below min.insync.replicas. Find which brokers are down or lagging (--under-replicated-partitions), check their disks, GC and network, and bring them back. Never "fix" it by lowering min.insync.replicas on important topics.
3. A broker's disk is filling
$ kafka-log-dirs.sh --bootstrap-server b:9092 --describe --topic-list orders | head
Find the biggest partitions. Short term: lower retention on the offending topic or add disk. Long term: rebalance partitions (Cruise Control), add brokers, use tiered storage, set per-topic retention.bytes.
4. Clients connect, then time out
The advertised listeners are wrong or unreachable from the client (lesson 13). Test with:
$ kafka-broker-api-versions.sh --bootstrap-server kafka.example.com:9094 --command-config client.properties
It must list every broker. Also check TLS trust (wrong CA) and that security protocols match on both sides.
5. RecordTooLargeException
The record is larger than the producer's max.request.size or the broker/topic message.max.bytes / max.message.bytes. Prefer storing large payloads elsewhere and sending a reference; if you raise limits, raise them consistently (producer, topic, consumer max.partition.fetch.bytes).
6. Authorization errors
TopicAuthorizationException or GroupAuthorizationException: the principal lacks an ACL. Check the exact principal string in the broker's authorizer log, then the ACLs (kafka-acls.sh --list --principal User:…).
7. One broker is much busier than the others
Leadership or partitions are unbalanced, often after a restart. Run a preferred leader election (lesson 8) and, for partitions, a Cruise Control rebalance.
8. Controller problems
ActiveControllerCount sum is not 1, or topic creation hangs. Check kafka-metadata-quorum.sh describe --status and --replication: do a majority of controllers run, and are they caught up?
Fix the cause, not the alarm
Lowering min.insync.replicas, enabling unclean leader election or deleting consumer groups can make an alert disappear while losing data. Write these down as break-glass actions that need a second person.
Try it: an incident drill
- On the 3-broker lab cluster, run a consumer group and a steady producer (perf test with
--throughput 1000). - Stop one broker. Which numbers change? Run
--under-replicated-partitions. - Stop the consumer for two minutes and watch lag; restart it and watch it recover.
- Produce a record larger than 1 MB and read the error. Raise the topic's
max.message.bytesand try again: what else must change for consumers? - Write a one-page runbook for "consumer lag growing" based on what you saw.
Going deeper
- Track end-to-end latency (produce time to consume time, from record timestamps) as a user-facing SLO, not just broker metrics.
- Keep a per-topic view: owner, throughput, size, consumer groups and lag. It answers most "is Kafka slow?" questions quickly.
- Use synthetic canary producers and consumers on every cluster to detect problems before users do.
Recap
- Page on offline partitions, under-min-ISR partitions and controller count; ticket on under-replicated partitions, disk and lag.
- Watch broker idle percentages and request latency for saturation.
- Collect with the JMX exporter and a lag exporter; ship logs.
- Most incidents are lag, ISR loss, disk, advertised listeners, record size or ACLs; each has a quick diagnostic command.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.