Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Kafka Operations Troubleshooting

Quick troubleshooting guide for operational issues.


quick-health-check.sh
#!/bin/bash
BOOTSTRAP=${1:-"localhost:9092"}
echo "=== Kafka Quick Health Check ==="
# Connectivity
echo -n "Connectivity: "
kafka-broker-api-versions.sh --bootstrap-server $BOOTSTRAP > /dev/null 2>&1 \
&& echo "OK" || echo "FAILED"
# Offline partitions
OFFLINE=$(kafka-topics.sh --bootstrap-server $BOOTSTRAP \
--describe --unavailable-partitions 2>/dev/null | grep -c "Topic:")
echo "Offline partitions: $OFFLINE"
# Under-replicated
URP=$(kafka-topics.sh --bootstrap-server $BOOTSTRAP \
--describe --under-replicated-partitions 2>/dev/null | grep -c "Topic:")
echo "Under-replicated: $URP"

Symptoms: UnderReplicatedPartitions > 0

Quick Check:

Terminal window
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --under-replicated-partitions

Common Causes:

CauseCheckResolution
Broker downBroker connectivityRestart broker
Slow brokerDisk I/O, CPUAddress bottleneck
Network issuesping, netstatFix connectivity
Large messagesMessage sizeIncrease replica.fetch.max.bytes

Symptoms: Lag increasing over time

Quick Check:

Terminal window
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--describe --group my-group

Common Causes:

CauseCheckResolution
Slow processingConsumer metricsOptimize processing
Too few consumersConsumer countAdd consumers
RebalancingGroup stateFix rebalance storms
External dependencyExternal latencyAdd buffering

Symptoms: TimeoutException in producer

Quick Check:

Terminal window
# Check broker health
kafka-broker-api-versions.sh --bootstrap-server kafka:9092
# Check partition leaders
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --topic my-topic

Common Causes:

CauseCheckResolution
Broker unavailableBroker statusRestart broker
No leaderPartition describeWait for election
ISR too smallmin.insync.replicasFix broker health
Network issuesConnectivityFix network

Symptoms: Consumers constantly rebalancing

Quick Check:

Terminal window
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--describe --group my-group --state

Common Causes:

CauseCheckResolution
Session timeoutProcessing timeIncrease max.poll.interval.ms
Consumer crashesConsumer logsFix stability
Heartbeat issuesNetworkCheck connectivity
GC pausesGC logsTune JVM

Resolution:

# Increase timeouts
max.poll.interval.ms=600000
session.timeout.ms=45000
heartbeat.interval.ms=3000
# Use cooperative rebalancing
partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor
# Static membership
group.instance.id=consumer-1

Symptoms: Request latency exceeds SLA

Quick Check:

Terminal window
# Check broker metrics
# kafka.network:type=RequestMetrics,name=TotalTimeMs

Common Causes:

CauseCheckResolution
Disk I/OiostatFaster disks
Networknetstat, pingFix network
GC pausesGC logsTune JVM
Request queueRequestQueueTimeMsMore network threads

Symptoms: No space left on device

Quick Check:

Terminal window
df -h /var/kafka-logs
du -sh /var/kafka-logs/*

Resolution:

Terminal window
# Reduce retention
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type topics --entity-name big-topic \
--alter --add-config retention.ms=86400000
# Delete old topics
kafka-topics.sh --bootstrap-server kafka:9092 \
--delete --topic unused-topic
# Add storage
# Mount additional disk

Terminal window
# Recent errors
grep "ERROR" /var/log/kafka/server.log | tail -50
# Specific exception
grep "OutOfMemoryError" /var/log/kafka/server.log
# Time-based search
grep "2024-01-15 10:" /var/log/kafka/server.log | grep ERROR
PatternMeaningAction
OutOfMemoryErrorHeap exhaustedIncrease heap
KafkaStorageExceptionDisk failureCheck disk
NotLeaderOrFollowerStale metadataUsually transient
ISR shrunkReplica fell behindCheck broker

Terminal window
# Check for port conflict
netstat -tlnp | grep 9092
# Check log for errors
tail -100 /var/log/kafka/server.log | grep -E "ERROR|FATAL"
# Verify disk space
df -h /var/kafka-logs
# Check file descriptors
ulimit -n
Terminal window
# Identify offline partitions
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --unavailable-partitions
# Check replica status
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --topic affected-topic
# If broker recoverable, restart it
# If not, consider unclean election (data loss risk)
kafka-leader-election.sh --bootstrap-server kafka:9092 \
--election-type unclean \
--topic affected-topic --partition 0
Terminal window
# Check group state
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--describe --group stuck-group --state
# Force delete (consumers must be stopped)
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--delete --group stuck-group
# Recreate with offset reset if needed