Home/Learn/Apache Kafka/Monitoring with Prometheus & Grafana

Monitoring with Prometheus & Grafana

Intermediate
Administration

Kafka exposes hundreds of JMX metrics. Export them to Prometheus via JMX Exporter and visualise in Grafana for production-grade observability of brokers, producers, and consumers.

Overview

JMX Exporter translates JMX metrics into Prometheus format. Grafana dashboards then visualise broker health, throughput, consumer lag, and replication state in real time.

Key Kafka Metrics to Monitor

Focus on broker health (UnderReplicatedPartitions), throughput, and consumer lag.

JMX Exporter + Prometheus alert
# JMX Exporter as Java agent
KAFKA_OPTS="-javaagent:/opt/jmx_prometheus_javaagent.jar=7071:/opt/kafka-jmx.yml"

# kafka-jmx.yml
rules:
  - pattern: 'kafka.server<type=ReplicaManager, name=UnderReplicatedPartitions><>Value'
    name: kafka_server_under_replicated_partitions

  - pattern: 'kafka.server<type=BrokerTopicMetrics, name=MessagesInPerSec, topic=(.+)><>OneMinuteRate'
    name: kafka_server_messages_in_per_sec
    labels:
      topic: "$1"

# Prometheus alert — consumer lag
- alert: KafkaConsumerHighLag
  expr: sum(kafka_consumer_group_lag{group="order-processor"}) > 10000
  for: 5m
  labels:
    severity: warning

Key Points to Remember

  • 1UnderReplicatedPartitions must always be 0 — any non-zero is critical
  • 2OfflinePartitionsCount > 0 means data is unavailable — page immediately
  • 3Consumer lag is the most actionable metric for application teams
  • 4RequestHandlerAvgIdlePercent < 30% indicates broker CPU saturation
  • 5Use kafka-lag-exporter for per-partition consumer lag in Prometheus

Interview Questions

Sign in to ask Aria
1

What Kafka metric would you alert on first to detect a broker failure?

MediumAmazon
2

What does UnderReplicatedPartitions > 0 mean and how urgent is it?

MediumConfluent
3

How do you expose Kafka JMX metrics to Prometheus?

EasyLinkedIn
4

What metrics would you include on a "Kafka health dashboard" for an on-call engineer?

HardNetflix
5

How would you differentiate a slow consumer from a fast producer when diagnosing growing lag?

HardUber

Ask Aria about Monitoring with Prometheus & Grafana

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…