Metrics

Kafka JMX, protocol exporter, and recording rule metrics dictionary.

The KAFKA module uses two kinds of metric sources, both registered under the same job=kafka scrape job: the JMX target (with a role label) collects the internal state of each JVM, while the protocol exporter target (without a role label) collects the state of the logical cluster, topics, partitions, and consumer groups over the Kafka protocol. The protocol exporter is placed only on the one or two broker-capable nodes with the smallest kafka_seq, and a single-broker cluster runs just one.

The JMX configuration is an allow-list: it exports only the JVM baseline and a bounded set of broker, replication, request-path, and KRaft metrics. High-cardinality per-client and per-partition JMX MBeans are deliberately excluded; partition detail is supplied by the protocol exporter.


Common Labels

Metric SourceCommon Labels
JMX target (:9404)job, cls, ins, ip, instance, role, node_id
Protocol exporter target (:9308)job, cls, ins, ip, instance

The job for both target types is kafka; whether a series carries the role label is what distinguishes the two.

Some metrics also carry dimensions such as topic, partition, broker, consumergroup, request, version, error, quantile, state, or operation.


Availability and Scrape Metrics

MetricTypeMeaning
kafka_upGauge/RecordingJMX target scrape availability: up{job="kafka",role=~".+"}
kafka_exporter_upGauge/RecordingProtocol exporter target scrape availability: up{job="kafka",role=""}
upGaugeVictoriaMetrics scrape status for the raw target
jmx_scrape_errorGaugeWhether the JMX Exporter’s last scrape errored; healthy value is 0
jmx_scrape_duration_secondsGaugeJMX scrape duration
jmx_scrape_cached_beansGaugeNumber of MBeans cached by the JMX Exporter
scrape_duration_secondsGaugeTime VictoriaMetrics took to scrape the exporter
scrape_samples_scrapedGaugeNumber of samples in this scrape

Protocol Exporter Metrics

The following metrics come from the protocol exporter target. Multiple exporters of the same cluster see the same logical cluster state, so any direct cluster aggregation must deduplicate by semantics rather than simply summing across all ins.

Broker and Topic

MetricTypeKey DimensionsMeaning
kafka_brokersGaugeClusterNumber of brokers discovered by the exporter
kafka_broker_infoGaugeid, address, etc.Broker info, carried on labels with value 1
kafka_topic_partitionsGaugetopicNumber of partitions in a topic
kafka_topic_partition_current_offsetGaugetopic, partitionPartition’s current log end offset
kafka_topic_partition_oldest_offsetGaugetopic, partitionPartition’s current earliest readable offset
kafka_topic_partition_leaderGaugetopic, partitionCurrent leader broker ID; used to spot anomalies when there is no leader
kafka_topic_partition_replicasGaugetopic, partition, brokerThe replica set assigned to a partition
kafka_topic_partition_in_sync_replicaGaugetopic, partition, brokerCurrent ISR members
kafka_topic_partition_under_replicated_partitionGaugetopic, partitionWhether the partition is under-replicated
kafka_topic_partition_leader_is_preferredGaugetopic, partitionWhether the current leader is the preferred replica

current_offset - oldest_offset estimates the currently retained offset span, but an offset count is not a byte count, and for a compacted topic it is not an exact message count either.

Consumer Group

MetricTypeKey DimensionsMeaning
kafka_consumergroup_membersGaugeconsumergroupCurrent member count of the group
kafka_consumergroup_current_offsetGaugeconsumergroup, topic, partitionGroup’s committed offset
kafka_consumergroup_current_offset_sumGaugeconsumergroup, topicSum of committed offsets
kafka_consumergroup_lagGaugeconsumergroup, topic, partitionPartition-level consumer lag
kafka_consumergroup_lag_sumGaugeconsumergroup, topicConsumer lag aggregated per group/topic

Ephemeral consumers that never commit an offset, clients that use external offset storage, and groups that have not yet consumed a topic will not necessarily produce these time series.

Exporter Itself

MetricTypeMeaning
kafka_exporter_build_infoGaugeExporter version, revision, and build info
process_*Gauge/CounterExporter process CPU, memory, FD, start time, etc.
go_*Gauge/CounterExporter Go runtime, GC, goroutine, and memory state
promhttp_metric_handler_*Counter/metrics request handling status

JMX: JVM Baseline

excludeJvmMetrics: false makes the JMX Exporter expose the standard JVM/process metrics. The Kafka Node dashboard mainly uses:

MetricMeaning
jvm_memory_used_bytesUsed memory, split by heap/non-heap and memory pool
jvm_memory_committed_bytesJVM committed memory
jvm_memory_max_bytesMaximum memory available to the JVM
jvm_gc_collection_seconds_countGC count
jvm_gc_collection_seconds_sumCumulative GC time
jvm_threads_stateThread count by thread state
jvm_threads_deadlockedNumber of detected deadlocked thread cycles
jvm_buffer_pool_used_bytesDirect/mapped buffer pool usage
process_cpu_seconds_totalCumulative CPU time of the Kafka JVM
process_open_fds / process_max_fdsOpen and maximum file descriptors
process_start_time_secondsKafka JVM start time

JMX: Broker Traffic

MetricTypeMeaning
kafka_server_broker_messages_in_totalCounterTotal messages received by the broker
kafka_server_broker_bytes_in_totalCounterTotal client bytes received by the broker
kafka_server_broker_bytes_out_totalCounterTotal client bytes sent by the broker
kafka_server_broker_replication_bytes_in_totalCounterTotal replication bytes received by the broker
kafka_server_broker_replication_bytes_out_totalCounterTotal replication bytes sent by the broker
kafka_server_broker_produce_requests_totalCounterTotal produce requests
kafka_server_broker_failed_produce_requests_totalCounterTotal failed produce requests
kafka_server_broker_fetch_requests_totalCounterTotal fetch requests
kafka_server_broker_failed_fetch_requests_totalCounterTotal failed fetch requests

These are broker-wide totals with no topic dimension, which keeps the JMX series count from growing with the number of topics. Topic-level offsets and progress come from the protocol exporter.


JMX: Replication and Storage

MetricTypeMeaning
kafka_server_replica_manager_under_replicated_partitionsGaugeNumber of partitions whose ISR is smaller than the assigned replica set
kafka_server_replica_manager_under_min_isr_partitionsGaugeNumber of partitions whose ISR is below min.insync.replicas
kafka_server_replica_manager_at_min_isr_partitionsGaugeNumber of partitions whose ISR is exactly min.insync.replicas
kafka_server_replica_manager_offline_replicasGaugeNumber of offline replicas on the current broker
kafka_server_replica_manager_partitionsGaugeNumber of replicas hosted by the current broker
kafka_server_replica_manager_leadersGaugeNumber of partitions led by the current broker
kafka_server_replica_manager_isr_shrinks_totalCounterTotal ISR shrink events
kafka_server_replica_manager_isr_expands_totalCounterTotal ISR expand events
kafka_server_replica_manager_failed_isr_updates_totalCounterTotal failed ISR updates
kafka_server_replica_manager_reassigning_partitionsGaugeNumber of leader partitions currently being reassigned
kafka_server_delayed_operation_purgatory_sizeGaugeNumber of delayed operations waiting, split by operation
kafka_log_manager_offline_log_directoriesGaugeNumber of log directories Kafka has marked offline

Under Replicated means the replicas are not all in sync. Under Min ISR is more serious: the write-availability or durability condition has fallen below the configured minimum ISR. At Min ISR has not crossed the line yet, but there is no remaining replica headroom.


JMX: Request Path

MetricTypeExtra LabelsMeaning
kafka_network_request_totalCounterrequest, versionTotal requests per Kafka API
kafka_network_request_errors_totalCounterrequest, errorTotal error responses per API/error code
kafka_network_request_total_time_secondsGaugerequest, version, quantileTotal API time at P50/P95/P99
kafka_network_request_queue_sizeGaugeNumber of requests waiting for a request handler
kafka_network_response_queue_sizeGaugeNumber of responses waiting for a network processor
kafka_server_request_handler_idle_ratioGaugeAverage request-handler idle ratio
kafka_network_processor_idle_ratioGaugeAverage network-processor idle ratio

When investigating high latency, look at request volume, error codes, P95/P99, both queues, handler/processor idle, GC, CPU, disk I/O, and network together. A low idle ratio alone is not enough to pinpoint where the bottleneck is.


JMX: KRaft and Broker Metadata

MetricTypeMeaning
kafka_server_raft_stateGaugeThe current member’s KRaft state, expressed via the state label
kafka_server_raft_current_leaderGaugeCurrent KRaft leader node ID; -1 means unknown
kafka_server_raft_current_epochGaugeCurrent KRaft epoch
kafka_server_raft_high_watermarkGaugeMetadata log high watermark
kafka_server_raft_log_end_offsetGaugeMetadata log end offset
kafka_server_broker_metadata_last_applied_record_lag_secondsGaugeTime lag of the broker applying metadata records
kafka_server_broker_metadata_load_errors_totalCounterTotal broker metadata load errors
kafka_server_broker_metadata_apply_errors_totalCounterTotal broker metadata image apply errors
kafka_server_metadata_snapshot_bytesGaugeSize of the most recently generated or loaded metadata snapshot
kafka_server_metadata_snapshot_age_secondsGaugeAge of the most recent metadata snapshot

log_end_offset - high_watermark helps gauge metadata commit lag; also factor in the member role, current leader, epoch, and controller event latency.


JMX: Controller

These MBeans exist only in Kafka processes that carry the controller role:

MetricTypeMeaning
kafka_controller_active_controller_countGauge1 on the active controller, 0 on the others
kafka_controller_fenced_broker_countGaugeNumber of fenced brokers observed by the active controller
kafka_controller_active_broker_countGaugeNumber of active brokers
kafka_controller_global_topic_countGaugeNumber of topics observed by the controller
kafka_controller_global_partition_countGaugeNumber of partitions observed by the controller
kafka_controller_offline_partition_countGaugeNumber of offline non-internal partitions
kafka_controller_preferred_replica_imbalance_countGaugeNumber of partitions whose leader is not the preferred replica
kafka_controller_metadata_errors_totalCounterTotal controller metadata processing errors
kafka_controller_last_applied_record_lag_secondsGaugeTime lag of the controller applying metadata records
kafka_controller_timed_out_broker_heartbeats_totalCounterTotal broker heartbeat timeouts
kafka_controller_elections_totalCounterTotal new active-controller elections observed by this node
kafka_controller_unclean_leader_elections_totalCounterTotal unclean leader elections
kafka_controller_event_queue_time_secondsGaugeController event queue time at P50/P95/P99
kafka_controller_event_processing_time_secondsGaugeController event processing time at P50/P95/P99

A healthy cluster should have exactly one active controller. Any increase in offline_partition_count, metadata_errors_total, or unclean_leader_elections_total should be treated as a priority.


Recording Rule Metrics

Offset Progress

MetricAggregation LevelWindowMeaning
kafka:topic:msg_rate1mTopic/Exporter1mForward growth rate of current offset
kafka:topic:msg_rate5mTopic/Exporter5mForward growth rate of current offset
kafka:ins:msg_rate1mExporter instance1mMessage append rate in the instance view
kafka:ins:msg_rate5mExporter instance5mMessage append rate in the instance view
kafka:cls:msg_rate1mLogical cluster1mMessage append rate, deduplicated across exporters
kafka:cls:msg_rate5mLogical cluster5mMessage append rate, deduplicated across exporters
kafka:topic:csg_rate1mGroup/Topic/Exporter1mForward growth rate of commit offset
kafka:topic:csg_rate5mGroup/Topic/Exporter5mForward growth rate of commit offset
kafka:ins:csg_rate1mExporter instance1mConsumer commit rate in the instance view
kafka:ins:csg_rate5mExporter instance5mConsumer commit rate in the instance view
kafka:cls:csg_rate1mLogical cluster1mConsumer commit rate, deduplicated across exporters
kafka:cls:csg_rate5mLogical cluster5mConsumer commit rate, deduplicated across exporters

JVM and Broker

MetricMeaning
kafka:ins:jvm_heap_used_ratioHeap used / heap max
kafka:ins:jvm_cpu_cores5-minute JVM CPU core consumption
kafka:ins:jvm_gc_time_rate5m5-minute GC time rate
kafka:ins:messages_in_rate5mBroker 5-minute message receive rate
kafka:ins:bytes_in_rate5mBroker 5-minute inbound client byte rate
kafka:ins:bytes_out_rate5mBroker 5-minute outbound client byte rate

Cardinality and Interpretation Notes

  • Do not directly sum multiple kafka_exporter results for the same cls; they may be duplicate views of the same cluster.
  • kafka_topic_partition_current_offset is an offset, not an exact count of bytes, requests, or business events.
  • Consumer lag covers only groups that are visible in Kafka and have committed an offset.
  • A controller-only node lacking broker metrics and protocol exporter metrics is a normal role difference; a broker that was not selected lacking protocol exporter metrics is a normal result of placement.
  • When a given MBean does not exist in a specific Kafka version/role, the corresponding JMX series will not appear either; interpret this together with role.
  • Per-client/per-partition JMX metrics are excluded by the allow-list to avoid unpredictable time-series cardinality.

For how to use the dashboards and alerts, see Monitoring.