Monitoring

Kafka JMX Metrics: The Ones That Actually Matter

A single Kafka broker exposes thousands of JMX metrics, most of them per topic and per partition. Collect everything and you drown in cardinality; collect too little and you miss the outage. This is the shortlist that covers almost every real incident.

Published November 20, 2026 · 7 min read · KLogic Team

Kafka publishes its internals through Java Management Extensions (JMX). Every broker, producer, consumer, Connect worker and Streams application registers MBeans you can read with JConsole, a Prometheus JMX exporter or a monitoring agent. The problem is volume: per-topic and per-partition metrics multiply quickly, and a cluster with a few thousand partitions can expose hundreds of thousands of series. The answer is to collect a small set of cluster-wide signals at full resolution and keep per-partition detail for the few metrics that need it.

Cluster health: is anything broken right now?

These are the metrics that should be on your first dashboard and behind your first alerts.

MetricMBeanWhy it matters
UnderReplicatedPartitionskafka.server:type=ReplicaManager,name=UnderReplicatedPartitionsPartitions led by this broker with missing in-sync replicas. Sum across brokers. Should be 0.
UnderMinIsrPartitionCountkafka.server:type=ReplicaManager,name=UnderMinIsrPartitionCountPartitions where acks=all writes now fail. Page on any non-zero value.
OfflinePartitionsCountkafka.controller:type=KafkaController,name=OfflinePartitionsCountPartitions without a leader. Reported by the active controller.
ActiveControllerCountkafka.controller:type=KafkaController,name=ActiveControllerCountExactly one controller across the cluster should report 1.
UncleanLeaderElectionsPerSeckafka.controller:type=ControllerStats,name=UncleanLeaderElectionsPerSecAny unclean election means acknowledged data may have been lost.

If you only alert on five things, alert on these. Our guide to under-replicated partitions covers what to do when the first one fires.

Throughput: how much work is the cluster doing?

MetricMBeanWhy it matters
MessagesInPerSeckafka.server:type=BrokerTopicMetrics,name=MessagesInPerSecRecords written per second. The best single measure of producer load.
BytesInPerSec / BytesOutPerSeckafka.server:type=BrokerTopicMetrics,name=BytesInPerSecNetwork and disk load. Bytes out includes consumer fetches, so it is usually a multiple of bytes in.
TotalProduceRequestsPerSeckafka.server:type=BrokerTopicMetrics,name=TotalProduceRequestsPerSecRequest rate. A rising request rate with flat bytes means producers are batching poorly.
FailedProduceRequestsPerSeckafka.server:type=BrokerTopicMetrics,name=FailedProduceRequestsPerSecShould stay near zero. Spikes point at authorisation, sizing or availability problems.

These exist both cluster-wide and per topic (add a topic= key). Collect the cluster-wide versions always and per-topic versions only for the topics you care about, or use a tool that aggregates them for you.

Saturation: is the broker running out of headroom?

Brokers rarely fail outright. They saturate first, and latency climbs long before anything errors. These metrics show how busy the broker's threads are:

MetricMBeanWhy it matters
RequestHandlerAvgIdlePercentkafka.server:type=KafkaRequestHandlerPool,name=RequestHandlerAvgIdlePercentShare of time I/O threads are idle. Below 30% sustained means the broker is close to its limit.
NetworkProcessorAvgIdlePercentkafka.network:type=SocketServer,name=NetworkProcessorAvgIdlePercentSame idea for network threads. Low values cause client timeouts.
RequestQueueSizekafka.network:type=RequestChannel,name=RequestQueueSizeRequests waiting for an I/O thread. A growing queue is the queueing that becomes latency.
TotalTimeMs (Produce, FetchConsumer, FetchFollower)kafka.network:type=RequestMetrics,name=TotalTimeMs,request=ProduceEnd-to-end request time, with percentiles. Compare p99 against your latency target.

TotalTimeMs is the sum of several components you can also collect: RequestQueueTimeMs, LocalTimeMs, RemoteTimeMs and ResponseSendTimeMs. When produce latency jumps, the component that grew tells you where to look: queue time means busy threads, local time means slow disks, and remote time means slow followers when producers use acks=all.

Replication and leadership

MetricMBeanWhy it matters
IsrShrinksPerSec / IsrExpandsPerSeckafka.server:type=ReplicaManager,name=IsrShrinksPerSecReplica churn. Frequent shrink and expand pairs mean an unstable broker or network.
LeaderCount / PartitionCountkafka.server:type=ReplicaManager,name=LeaderCountPer-broker balance. Big differences between brokers mean skewed load.
LeaderElectionRateAndTimeMskafka.controller:type=ControllerStats,name=LeaderElectionRateAndTimeMsLeadership changes. Spikes outside deployments signal brokers dropping out.

Storage

Kafka exposes per-partition log size as kafka.log:type=Log,name=Size,topic=*,partition=*, which is useful for finding the biggest topics but too detailed to graph cluster-wide. Pair it with filesystem usage from the operating system and LogFlushRateAndTimeMs for flush latency. See monitoring Kafka disk usage for how to forecast growth.

JVM metrics you still need

Kafka runs on the JVM, and long garbage collection pauses look like broker outages to clients and followers:

  • GC time and count from java.lang:type=GarbageCollector,name=*. Watch the longest pause, not only the average.
  • Heap usage after GC. A floor that keeps rising points at a leak or an undersized heap.
  • Open file descriptors. Each segment file and connection uses one; running out takes the broker down.

Client metrics: the half most teams forget

Broker metrics tell you the cluster is healthy. Client metrics tell you the applications are. The most useful ones:

  • Consumer: records-lag-max from kafka.consumer:type=consumer-fetch-manager-metrics, plus rebalance-rate-per-hour and time-between-poll-max from the coordinator metrics. See our guide to consumer rebalancing.
  • Producer: record-error-rate, record-retry-rate, request-latency-avg and record-queue-time-avg from kafka.producer:type=producer-metrics.

Consumer lag is better measured from the broker side, by comparing committed offsets with log end offsets, because it keeps working when a consumer is down. Client metrics vanish exactly when the consumer you need to see has crashed.

KRaft clusters

In KRaft mode the controller quorum replaces ZooKeeper, and the controllers publish their own metrics, including Raft state and commit latency. Add the controller nodes to your scrape targets and alert when the quorum has no leader or when metadata replication falls behind. Our KRaft migration guide lists the specific signals.

Collecting JMX metrics without a cardinality explosion

The Prometheus JMX exporter turns MBeans into time series using rules. The default "export everything" approach is the main reason Kafka monitoring becomes slow and expensive. A better rule file has three parts:

  1. Cluster-wide metrics, always. Everything in the health, saturation and replication tables above. These are a few dozen series per broker.
  2. Per-topic throughput for an allow-list. MessagesInPerSec and BytesInPerSec per topic for the topics you actually look at.
  3. Per-partition metrics only where needed. Log size per partition, collected less often, for storage analysis.
# jmx_exporter rules (excerpt)
lowercaseOutputName: true
rules:
  - pattern: kafka.server<type=ReplicaManager, name=(UnderReplicatedPartitions|UnderMinIsrPartitionCount|LeaderCount|PartitionCount)><>Value
    name: kafka_server_replicamanager_$1
  - pattern: kafka.controller<type=KafkaController, name=(ActiveControllerCount|OfflinePartitionsCount)><>Value
    name: kafka_controller_$1
  - pattern: kafka.server<type=KafkaRequestHandlerPool, name=RequestHandlerAvgIdlePercent><>OneMinuteRate
    name: kafka_server_request_handler_idle_ratio
  - pattern: kafka.server<type=BrokerTopicMetrics, name=(MessagesInPerSec|BytesInPerSec|BytesOutPerSec)><>OneMinuteRate
    name: kafka_server_brokertopicmetrics_$1_rate

The last rule has no topic key, so it matches only the cluster-wide aggregate. Add a second, topic-specific rule with an allow-list when you need per-topic detail. Scraping every 30 to 60 seconds is enough for almost all of these.

Percentile metrics such as request TotalTimeMs are calculated inside the broker over a sliding window. Treat them as approximate, and compare like with like (the same percentile over time) rather than averaging them across brokers.

A sensible starting set

  1. Alert: under-min-ISR, offline partitions, active controller count, unclean elections.
  2. Warn: under-replicated partitions for more than 10 minutes, request handler idle below 30%, disk above 80%.
  3. Dashboard: bytes and messages in and out, produce and fetch p99 latency, leader balance, consumer lag.
  4. Investigate on demand: per-partition sizes, per-topic throughput, request time breakdowns.

You can build this with a JMX exporter, Prometheus and a few dozen dashboard panels, or let a Kafka-specific tool do it. KLogic collects these broker, topic and consumer metrics, presents them per cluster and ships alert rules for the critical ones, so the shortlist above is covered from day one.

Kafka Connect and Kafka Streams metrics

If you run Connect or Streams, they need their own short list, because broker metrics will look healthy while a connector task is failed or a Streams thread has died.

  • Connect workers publish metrics under kafka.connect: connector and task counts, task startup failures, and per-task status and error counters. Alert on any task in a failed state and on rising record error totals. Our Connect best practices cover the rest.
  • Kafka Streams publishes thread, task and state store metrics under kafka.streams, including process and commit rates and latencies. Alert on stream threads that stop processing and on commit latency rising, and watch consumer lag for the application's input topics. See Kafka Streams monitoring.

Common questions

How do I enable JMX on a Kafka broker?

Set the JMX_PORT environment variable before starting the broker for remote JMX access, or attach the Prometheus JMX exporter as a Java agent so metrics are served over HTTP instead. The agent approach is easier to secure and scrape.

Which single Kafka metric is most important?

If you can only watch one, watch under-min-ISR partitions, because it means writes are failing. In practice, pair it with offline partitions and consumer lag.

Are Kafka JMX metrics the same in KRaft mode?

Broker metrics are largely the same. KRaft adds controller and Raft metrics on the controller nodes and removes ZooKeeper client metrics. See our KRaft monitoring guide.

How do I get consumer lag from JMX?

Client JMX gives records-lag-max per consumer, but it disappears when the consumer is down. Broker-side lag, comparing committed offsets with log end offsets through the admin API, is more reliable for alerting.

How many metrics should I collect per broker?

For dashboards and alerting, a few hundred series per broker is plenty. If you are collecting tens of thousands, most are per-partition series you never query. A tool like KLogic picks the useful set for you.

See your Kafka clusters the way KLogic does

Consumer lag, replication health, alerts and AI-assisted debugging in one place, for self-hosted Kafka, AWS MSK and Confluent.

Free 14-day trial · No credit card required