Monitoring Kafka: JMX Metrics, Prometheus, Grafana and Consumer Lag Alerts

Apache Kafka 18 min min read Updated: Nov 17, 2026 Intermediate
Monitoring Kafka: JMX Metrics, Prometheus, Grafana and Consumer Lag Alerts
Intermediate Topic 1 of 3

What to Monitor

text Layer 1: Host CPU, memory, disk space and I/O, network, file descriptors Layer 2: JVM heap, GC pause time, threads Layer 3: Broker replication health, request latency, throughput, controller state Layer 4: Topics bytes in/out per topic, partitions, size Layer 5: Clients producer error and latency metrics, consumer lag Layer 6: Business end-to-end latency, events per minute, freshness

Most Important Broker Metrics

JMX metric (kafka.server...)Healthy valueAlert when
ReplicaManager UnderReplicatedPartitions0> 0 for more than a few minutes
ReplicaManager UnderMinIsrPartitionCount0> 0 (producers with acks=all fail)
KafkaController OfflinePartitionsCount0> 0 immediately
KafkaController ActiveControllerCountExactly 1 across the clusterNot equal to 1
ReplicaManager IsrShrinksPerSec / IsrExpandsPerSecNear 0Sustained activity (ISR flapping)
BrokerTopicMetrics BytesInPerSec / BytesOutPerSec / MessagesInPerSecMatches normal loadLarge drops or spikes versus baseline
RequestMetrics TotalTimeMs (Produce, FetchConsumer)p99 within your SLOp99 doubles from baseline
KafkaRequestHandlerPool RequestHandlerAvgIdlePercentAbove 0.3Below 0.2 (handler threads saturated)
SocketServer NetworkProcessorAvgIdlePercentAbove 0.3Below 0.2
Log LogFlushRateAndTimeMsLowHigh values show slow disks

Host and JVM

  • Disk free per log directory (alert at 70 percent warning, 85 percent critical)
  • Disk latency and utilisation (iostat), network errors and saturation
  • Open file descriptors versus the limit
  • GC pause time (alert when pauses reach seconds) and heap usage after GC
  • Page cache hit behaviour (reads going to disk for consumers that should be near the head)

Client Metrics

ClientMetrics
Producerrecord-error-rate, record-retry-rate, request-latency-avg, batch-size-avg, buffer-available-bytes, produce-throttle-time-avg
Consumerrecords-lag-max, fetch-rate, commit-latency-avg, rebalance-total, last-poll-seconds-ago, records-consumed-rate

Expose these from your applications through Micrometer (Spring Boot) or the OpenTelemetry Java agent into Prometheus.

Collecting Metrics with Prometheus

Kafka exposes metrics over JMX. Run the Prometheus JMX Exporter as a Java agent in each broker, which turns MBeans into an HTTP endpoint.

bash # kafka-jmx.yml (rules shortened) lowercaseOutputName: true rules: - pattern: kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+), partition=(.*)><>Value name: kafka_server_$1_$2 labels: { clientId: "$3", topic: "$4", partition: "$5" } - pattern: kafka.server<type=(.+), name=(.+)><>Value name: kafka_server_$1_$2 - pattern: kafka.controller<type=(.+), name=(.+)><>Value name: kafka_controller_$1_$2 export KAFKA_OPTS="-javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent.jar=7071:/opt/jmx_exporter/kafka-jmx.yml" # metrics now at http://broker1:7071/metrics
yaml # prometheus.yml scrape_configs: - job_name: kafka-brokers static_configs: - targets: ["broker1:7071", "broker2:7071", "broker3:7071"] - job_name: kafka-exporter # consumer lag and topic offsets (danielqsj/kafka-exporter) static_configs: - targets: ["kafka-exporter:9308"]

Consumer Lag Monitoring

Consumer lag is usually the most important application-level signal. Collect it from outside the consumers, so you also see groups that have stopped completely.

ToolNotes
kafka-exporter (Prometheus)Exposes kafka_consumergroup_lag and topic offsets. Simple to run
Burrow (LinkedIn)Evaluates lag trends over time and reports OK, warning or error status per group, good at avoiding false alarms
Kafka UI, AKHQ, Redpanda Console, KafdropWeb interfaces to inspect topics, groups and messages
Cloud or vendor toolsConfluent Control Center, MSK and Cloud Monitoring dashboards

Alert Rules (Prometheus)

yaml groups: - name: kafka rules: - alert: KafkaUnderReplicatedPartitions expr: sum(kafka_server_replicamanager_underreplicatedpartitions) > 0 for: 5m labels: { severity: warning } annotations: { summary: "Under-replicated partitions on the Kafka cluster" } - alert: KafkaOfflinePartitions expr: sum(kafka_controller_kafkacontroller_offlinepartitionscount) > 0 for: 1m labels: { severity: critical } - alert: KafkaNoActiveController expr: sum(kafka_controller_kafkacontroller_activecontrollercount) != 1 for: 2m labels: { severity: critical } - alert: KafkaConsumerLagHigh expr: sum by (consumergroup, topic) (kafka_consumergroup_lag) > 10000 for: 10m labels: { severity: warning } - alert: KafkaDiskAlmostFull expr: (node_filesystem_avail_bytes{mountpoint="/var/lib/kafka"} / node_filesystem_size_bytes{mountpoint="/var/lib/kafka"}) < 0.2 for: 10m labels: { severity: critical }
Alert on lag growth, not only size: A group with lag 50,000 that is shrinking is healthy after a burst. A group with lag 500 that is growing for an hour is a problem. Use deriv() or Burrow-style trend checks, and alert when lag has not moved for a group that should be active.

Grafana Dashboard Layout

RowPanels
Cluster healthActive controller, offline partitions, under-replicated partitions, brokers online
ThroughputMessages in/s, bytes in/s, bytes out/s per broker and per top topics
LatencyProduce and fetch p50, p99 total time, request queue time
ResourcesCPU, heap, GC time, disk used and I/O, network
ConsumersLag per group, rebalance count, consumption rate
BusinessEnd-to-end latency from event timestamp to processing time

Daily Health Checklist

  • No offline or under-replicated partitions, one active controller
  • Disk growth in line with plan, no volume above 70 percent
  • Consumer lag stable for all important groups
  • No unusual error rates or throttling
  • Certificates valid for at least 30 more days
  • Backups and mirror lag fine (if used)

Conclusion

Monitor the host, JVM, brokers, topics and clients. Use the JMX exporter with Prometheus and Grafana, watch under-replicated and offline partitions, controller count, request latency and disk, monitor consumer lag from outside, and alert on trends.

Quick Summary: URP, offline, controller=1, latency, disk, consumer lag; JMX exporter + Prometheus + Grafana.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators