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:
kafka_brokers: broker countkafka_topic_partitions: partitions per topickafka_topic_partition_in_sync_replica: in-sync replicas (ISR) per partitionkafka_topic_partition_leader: leader status per partitionkafka_topic_partition_under_replicated_partition: under-replication statusThese metrics power the Overview and Partitions & replication sections of the Kafka dashboard.
The collector connects to brokers from the host network. Running Kafka in Docker? Publish the broker port and advertise a listener host clients can follow:
Containers on the compose network keep connecting to kafka:19092.
Seeing your Kafka as Configuration required or Unreachable? Go to Sources β your collector β Configure β Collect metrics, open the Kafka target, and point it at a broker address reachable from the host, e.g. 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.
Broker-level performance metrics like throughput, request rates, controller state, and storage live in Kafka's JMX (Java Management Extensions) and aren't exposed outside the Java process by default. Deploy the Prometheus JMX exporter as a Java agent on each broker to light up the rest of the Kafka dashboard:
kafka_server_brokertopicmetrics_*: bytes and messages in/out, per topickafka_controller_kafkacontroller_*: active controller, broker count, offline partitionskafka_server_replicamanager_*: leader count, partition count, ISR changeskafka_network_requestmetrics_*: request rates per request typekafka_log_log_size: log size per topic and partitionDownload the JMX exporter agent JAR to each Kafka broker:
Save the following configuration next to the agent JAR:
Rules are applied first-match-wins. Keep the specific patterns above the generic catch-alls, otherwise per-topic metric names get mangled.
Add the agent to Kafka's JVM options. The exporter serves Prometheus metrics on port 7071:
Restart Kafka and verify the endpoint:
Every Kafka command-line tool started in the same environment, including Docker healthchecks like kafka-broker-api-versions.sh, picks up KAFKA_OPTS. It then tries to attach a second agent to the busy port, and crashes.
To resolve this, clear the variable for CLI invocations:
The collector scrapes the endpoint from the host network every 30 seconds. When Kafka runs in a container, publish port 7071 so the endpoint is reachable on the host.
Using the same service name as the automatically discovered Kafka service groups both metric sources under one service in Better Stack.
Within a few minutes, metrics like kafka_server_brokertopicmetrics_bytesinpersec_total and kafka_controller_kafkacontroller_activecontrollercount appear in your collector source, and the scrape target shows as Active in Configure β Collect metrics.
Check out the Kafka dashboard: broker throughput, controller state, partition health, and storage in one place. Charts plotting rates need two scrapes before drawing the first point. Give them a minute.
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.