Apache Kafka
Monitor Apache Kafka brokers, topics, partitions, and consumer group lag with the OpenTelemetry Collector Kafka metrics receiver.
Overview
Apache Kafka is an open-source distributed event streaming platform used to build real-time data pipelines and event-driven applications. Producers append records to partitioned, replicated topics, and consumer groups read them at their own pace, which makes Kafka the backbone that decouples many services from each other.
Because so much depends on Kafka, problems there tend to show up somewhere else first: a consumer group that falls behind delays every downstream system, and partitions that lose in-sync replicas put data durability at risk. The OpenTelemetry Collector's Kafka metrics receiver connects to your cluster as a client and reports brokers, topics, partitions, and consumer groups to Dash0, without any agent running on the brokers themselves.
Use Cases
- Monitor consumer group lag per topic and partition to catch slow or stuck consumers before data goes stale.
- Track produce and consume throughput per topic, derived from partition and consumer group offsets.
- Analyze replication health by spotting partitions whose in-sync replicas fall below their replica count.
- Understand cluster shape over time, including broker count, topic partitioning, and consumer group membership.
Setup
Overview
The OpenTelemetry Collector's Kafka metrics receiver connects to your Kafka cluster as a regular client and uses the Kafka admin API to collect metrics about brokers, topics, partitions, and consumer groups. Nothing needs to be installed on the brokers: the collector only needs network access to the bootstrap servers and, on secured clusters, a client identity with read-only permissions.
The receiver has three scrapers, which you can enable in any combination:
- brokers: number of brokers in the cluster (
kafka.brokers). - topics: partitions per topic, current and oldest offset per partition, and replica and in-sync replica counts
(
kafka.topic.*,kafka.partition.*). - consumers: consumer group members, committed offsets, and lag per topic and partition
(
kafka.consumer_group.*).
In OpenTelemetry Collector Contrib v0.152.0 the receiver was renamed from kafkametrics to kafka_metrics. Newer
collectors still accept kafkametrics as a deprecated alias and log a warning. If you run a collector older than
v0.152.0, use kafkametrics as the receiver name in the examples below.
Prerequisites
Before setting up Kafka monitoring, ensure:
- Kafka 2.x, 3.x, or 4.x is running (ZooKeeper or KRaft mode) and its bootstrap servers are reachable from the collector.
- If your cluster uses authentication or ACLs, you have a client identity for the collector with
Describepermission on the cluster, the topics, and the consumer groups you want to monitor. The optional retention metrics also needDescribeConfigs. - The collector runs the OpenTelemetry Collector Contrib distribution , or a custom distribution that includes the Kafka metrics receiver.
You'll need an OpenTelemetry Collector deployed. Consider using:
Run a single collector instance for each Kafka cluster you monitor. The receiver reports cluster-wide state, so running it on every node (for example in a DaemonSet) produces duplicate data.
Collector Configuration
Add the Kafka metrics receiver to your collector configuration and include it in a metrics pipeline:
receivers:
kafka_metrics:
brokers:
- kafka-0.kafka-headless:9092
- kafka-1.kafka-headless:9092
cluster_alias: kafka-prod
collection_interval: 30s
scrapers:
- brokers
- topics
- consumers
service:
pipelines:
metrics:
receivers: [kafka_metrics]Configuration Options
- brokers: list of bootstrap servers the receiver connects to (default:
localhost:9092). - scrapers: which groups of metrics to collect. Required, with no default.
- cluster_alias: a name for the cluster, added to every metric as the
kafka.cluster.aliasresource attribute. Set it whenever you monitor more than one cluster so you can tell them apart in Dash0. - collection_interval: how often the receiver collects metrics (default:
1m). - topic_match: regular expression of topics to collect (default:
^[^_].*$, which skips internal topics such as__consumer_offsets). - group_match: regular expression of consumer groups to collect (default:
.*). - protocol_version: Kafka protocol version used by the client (default:
2.1.0).
On large clusters, use topic_match and group_match to limit collection to the topics and consumer groups you care
about. Partition and consumer lag metrics create one time series per partition, so cardinality grows with your
partition count.
Secured Clusters
For clusters that use SASL authentication over TLS, add auth and tls settings:
receivers:
kafka_metrics:
brokers:
- kafka.example.com:9093
cluster_alias: kafka-prod
scrapers:
- brokers
- topics
- consumers
auth:
sasl:
mechanism: SCRAM-SHA-512
username: ${env:KAFKA_USERNAME}
password: ${env:KAFKA_PASSWORD}
tls:
ca_file: /etc/kafka/certs/ca.pemThe receiver also supports PLAIN, SCRAM-SHA-256, and AWS_MSK_IAM_OAUTHBEARER (for Amazon MSK) SASL mechanisms,
Kerberos, and mutual TLS with tls.cert_file and tls.key_file.
Optional Metrics
The following metrics are disabled by default. Enable the ones you need under metrics:
receivers:
kafka_metrics:
# ...
metrics:
kafka.topic.replication_factor:
enabled: true
kafka.topic.min_insync_replicas:
enabled: true
kafka.topic.log_retention_period:
enabled: true
kafka.topic.log_retention_size:
enabled: true
kafka.broker.log_retention_period:
enabled: trueTo add the cluster's unique ID as the kafka.cluster.id resource attribute, enable it with
resource_attributes.kafka.cluster.id.enabled: true.
For more options, see the Kafka metrics receiver documentation .
Verification
- Check the collector logs for connection or authentication errors from the
kafka_metricsreceiver. - Navigate to Metrics Explorer in Dash0.
- Search for metrics with prefix
kafka.. - Confirm key metrics are visible:
kafka.brokers(brokers in the cluster)kafka.topic.partitions(partitions per topic)kafka.partition.current_offset(latest offset per partition)kafka.consumer_group.lag(consumer lag per group, topic, and partition)
Consumer group metrics only appear for groups that have committed offsets, so a new consumer group shows up after its first commit.
