Jestino Sam
Jestino Sam

Reputation: 602

Kafka Producer Metrics

I am running a Kafka producer in a local machine using my Intellij IDE & the producer will be producing a million records. While doing so, I want to capture the producer metrics in the below way:

enter image description here

I am aware about JMX port for kafka & I did try setting the Kafka JMX port to 9999. But I am not sure if we can get the metrics using JConsole or JVisualVM in the above way that I am expecting.

Can any one suggest any idea as to how can this be achieved?

Upvotes: 4

Views: 5159

Answers (1)

Mickael Maison
Mickael Maison

Reputation: 26910

In addition of JMX, the official Kafka clients also expose their metrics via the Java API, see the metrics() method to retrieve them all.

For example, to print all the metrics' names and values:

for (Entry<MetricName, ? extends Metric> entry : producer.metrics().entrySet()) {
    System.out.println(entry.getKey().name() + " : " + entry.getValue().metricValue());
}

Out of all the metrics, you are probably interested in outgoing-byte-rate, request-total and request-rate.

Upvotes: 8

Related Questions