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.
Monitor Apache Kafka with Better Stack collector. Broker discovery and partition health out of the box, full broker internals with the Prometheus JMX exporter.
Install Better Stack collector on the hosts running Kafka. The collector automatically discovers your brokers and starts collecting cluster metadata. No Kafka configuration needed:
These metrics power the Overview and Partitions & replication sections of the Kafka dashboard.
Brokers are discovered and reached automatically through the cluster network. No extra setup needed.
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.
kafka.localhost:9092.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.
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:
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.
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.
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:
Annotate the Kafka pod template and the collector discovers and scrapes the endpoint automatically:
Download the agent JAR next to the rules file:
Mount the folder, attach the agent, and publish the metrics port:
Restart Kafka and verify the endpoint:
Then add the endpoint as a scrape target in Better Stack:
kafka. The shared name groups both metric sources under one service.http://localhost:7071/metrics.The collector scrapes the endpoint from the host network every 30 seconds. That's why port 7071 is published.
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.
Clear the variable for CLI invocations:
Within a few minutes, metrics appear in your collector source, and the scrape target shows as Active in your collector's Configure β Collect metrics.
Check out the Kafka dashboard. You should see your broker throughput, controller state, partition health, and storage in one place.
Please let us know at hello@betterstack.com. We're happy to help! π
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.