简体   繁体   English

如何在 Java 中获取主题级别的 Kafka 指标?

[英]How can I get Kafka metrics at the topic level in Java?

I am trying to get Kafka metrics at the topic level in Java.我正在尝试在 Java 中获取主题级别的 Kafka 指标。 The kafka Docs show that I can get them using JMX but I am not sure how to do this. kafka Docs显示我可以使用 JMX 获取它们,但我不确定如何执行此操作。

The docs show the MBean as being kafka.producer:type=producer-topic-metrics,client-id="{client-id}",topic="{topic}" I am unsure of where to put the actual metric name that I am after, but have attempted it as such: "kafka.consumer:type=consumer-fetch-manager-metrics,client-id=\\"1\\",topic=\\"%s\\",name=\\"bytes-consumed-rate\\""文档显示 MBean 为kafka.producer:type=producer-topic-metrics,client-id="{client-id}",topic="{topic}"我不确定在哪里放置实际的度量名称我在追求,但已经尝试过: "kafka.consumer:type=consumer-fetch-manager-metrics,client-id=\\"1\\",topic=\\"%s\\",name=\\"bytes-consumed-rate\\""

I am also unsure of how to actually use the bean and where to specify the kafka cluster information.我也不确定如何实际使用 bean 以及在哪里指定 kafka 集群信息。

Thus far I've got this going for me... But the bean isn't actually doing anything because I dont know how to actually execute it.到目前为止,我已经为我准备好了……但是 bean 实际上并没有做任何事情,因为我不知道如何实际执行它。

        String metric = String.format("kafka.server:name=BytesInPerSec,topic=%s,type=BrokerTopicMetrics", topicName);
        try{
            ObjectName objectName = new ObjectName(metric);
            String s = objectName + " ^L";
            LOGGER.info(s);
        }
        catch(MalformedObjectNameException e){
            LOGGER.error("Malformed Object Exception: ", e);
        }
        return null;

Ideally I want to get out kafka metrics at the topic level as an object.理想情况下,我想将主题级别的 kafka 指标作为一个对象。 Any help would be greatly appreciated.任何帮助将不胜感激。

All the clients (Producer, Consumer, AdminClient) have methods called metrics() that exposes all the JMX metrics.所有客户端(Producer、Consumer、AdminClient)都具有称为metrics()方法,用于公开所有 JMX 指标。

For example, for the Producer, see metrics() that returns a Map of all existing metrics and their values.例如,对于 Producer,请参阅metrics()返回所有现有指标及其值的 Map。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM