通过使用 JmxTrans 添加基于 topicName(通配符)的自定义标签将 Kafka JMX 发送到 influxDb

Adding a custom tag based on topicName (wildcard) via using JmxTrans to send Kafka JMX to influxDb

基本上我想要实现的是获取 kafka 中所有主题的 MessageInPerSec 指标,并将自定义标签添加为 influx 数据库中的 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 将 topic 的通配符值用作单独标记并将其写入 InfluxDB 的足够文档。

您只需为 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
    }
  ]
}