Monitor Apache Kafka with Better Stack collector. Broker discovery and partition health out of the box, full broker internals with the Prometheus JMX exporter.
Start collecting Kafka metrics
Install Better Stack collector on the hosts running Kafka. The collector automatically discovers your brokers and starts collecting cluster metadata. No Kafka configuration needed:
Broker count
Partitions per topic
In-sync replicas (ISR) per partition
Leader status per partition
Under-replication status
These metrics power the Overview and Partitions & replication sections of the Kafka dashboard.
Basic Kafka metrics in Kubernetes
Brokers are discovered and reached automatically through the cluster network. No extra setup needed.
Advertise each broker with a fully qualified domain name the cluster can resolve, such as the broker's Kubernetes Service DNS name:
A bare hostname or localhost in KAFKA_ADVERTISED_LISTENERS only resolves inside the broker's own pod, so the collector and other clients elsewhere in the cluster can't reach it. Always advertise the Service FQDN, or point clients at a Kubernetes Service object.
Basic Kafka metrics in Docker Compose
The collector connects to brokers from the host network. Publish the broker port and advertise a listener host clients can follow:
Containers on the compose network keep connecting to kafka:19092.
Go to Sources → your collector → Configure → Collect metrics.
Click Collect metrics and select Kafka.
Set Service name to match your Kafka service, like kafka.
Set Endpoint to a broker address reachable from the host, like localhost:9092.
Use the broker address, not a metrics endpoint
The Kafka target is a connection to the Kafka protocol port, typically 9092. Don't point it at the JMX exporter port. The JMX exporter is connected separately as a Prometheus scrape target below.
Get full Kafka metrics with JMX exporter
Kafka keeps broker-level performance metrics in JMX (Java Management Extensions) and doesn't expose them by default.
Deploy the Prometheus JMX exporter as a Java agent on each broker to light up the rest of the Kafka dashboard:
Bytes and messages in/out, per topic
Active controller, broker count, offline partitions
Leader count, partition count, ISR changes
Request rates per request type
Log size per topic and partition
The setup is the same everywhere: put the agent JAR and a rules file on each broker, add the -javaagent flag to Kafka's JVM options, and let the collector scrape port 7071.
Create the rules file
Save the following configuration next to where the agent JAR will live:
Rules are applied first-match-wins. Keep the specific patterns above the generic catch-alls, otherwise per-topic metric names get mangled.
JMX exporter in Kubernetes
Fetch the agent in an init container and attach it to the broker container. Mount the rules file to /jmx-exporter/jmx-kafka-config.yaml, for example from a ConfigMap:
Then add the endpoint as a scrape target in Better Stack:
Go to Sources → your collector → Configure → Collect metrics.
Click Collect metrics and select Custom Prometheus exporter or service.
Set Service name to match your Kafka service, like kafka. The shared name groups both metric sources under one service.
Set Endpoint to http://localhost:7071/metrics.
The collector scrapes the endpoint from the host network every 30 seconds. That's why port 7071 is published.
Beware of Kafka CLI tools inheriting KAFKA_OPTS
Kafka CLI tools, including Docker healthchecks and Kubernetes probes calling scripts like kafka-broker-api-versions.sh, inherit KAFKA_OPTS and crash trying to attach a second agent to the busy port.