0

基本上我想要实现的是获取 kafka 中所有主题的 MessageInPerSec 指标,并将自定义标签添加为 influx db 中的 topicName 以便基于不基于“ObjDomain”定义的主题进行查询,下面是我的 JmxTrans配置,(注意使用主题的通配符来获取所有主题的数据 MessageInPerSec JMX 属性)

{
  "servers": [
    {
      "port": "9581",
      "host": "192.168.43.78",
      "alias": "kafka-metric",
      "queries": [
        {
          "outputWriters": [
            {
              "@class": "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory",
              "url": "http://192.168.43.78:8086/",
              "database": "kafka",
              "username": "admin",
              "password": "root"
            }
          ],
          "obj": "kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec,topic=*",
          "attr": [
            "Count",
            "MeanRate",
            "OneMinuteRate",
            "FiveMinuteRate",
            "FifteenMinuteRate"
          ],
          "resultAlias": "newTopic"
        }
      ],
      "numQueryThreads": 2
    }
  ]
}

在 Influx DB 中产生如下结果

[name=newTopic, time=1589425526087, tags={attributeName=FifteenMinuteRate,
 className=com.yammer.metrics.reporting.JmxReporter$Meter, objDomain=kafka.server,
 typeName=type=BrokerTopicMetrics,name=MessagesInPerSec,topic=backblaze_smart}, 
precision=MILLISECONDS, fields={FifteenMinuteRate=1362.9446063537794, _jmx_port=9581
}]

并使用配置中指定的整个 objDomain 创建标签,但我希望将主题作为单独的标签,如下所示

[name=newTopic, time=1589425526087, tags={attributeName=FifteenMinuteRate,
 className=com.yammer.metrics.reporting.JmxReporter$Meter, objDomain=kafka.server,
  topic=backblaze_smart,
 typeName=type=BrokerTopicMetrics,name=MessagesInPerSec,topic=backblaze_smart}, 
precision=MILLISECONDS, fields={FifteenMinuteRate=1362.9446063537794, _jmx_port=9581
}]

无法找到任何足够的文档来说明如何使用 jmxtrans 将主题的通配符值用作单独的标签并将其写入 InfluxDB。

4

1 回答 1

1

您只需为 Influx 输出编写器添加以下附加属性。只要确保您使用的是最新版本的 jmxtrans 版本。文档在这里:https ://github.com/jmxtrans/jmxtrans/wiki/InfluxDBWriter

“typeNames”:[“topic”],
“typeNamesAsTags”:“true”

我已经列出了您的配置以及上述修改。

{
  "servers": [
    {
      "port": "9581",
      "host": "192.168.43.78",
      "alias": "kafka-metric",
      "queries": [
        {
          "outputWriters": [
            {
              "@class": "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory",
              "url": "http://192.168.43.78:8086/",
              "database": "kafka",
              "username": "admin",
              "password": "root",
              "typeNames": ["topic"],
              "typeNamesAsTags": "true"
            }
          ],
          "obj": "kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec,topic=*",
          "attr": [
            "Count",
            "MeanRate",
            "OneMinuteRate",
            "FiveMinuteRate",
            "FifteenMinuteRate"
          ],
          "resultAlias": "newTopic"
        }
      ],
      "numQueryThreads": 2
    }
  ]
}
于 2020-09-21T17:57:53.240 回答