有没有办法根据 telegraf 输入写入 kafka 主题?

Is there a way to write to kafka topics based on telegraf input?

我想把agent采集到的数据根据​​输入的plugins写到kafka的不同topic中。能否根据telegram输入,将采集到的数据分别转发给kafka toics?

[global_tags]


[agent]
  interval = "20s"
  round_interval = true
  metric_batch_size = 10000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = "0s"
  hostname = ""
  omit_hostname = false


 [[outputs.kafka]]
   brokers = ["127.0.0.1:9092","127.0.0.1:9093"]
   #topic = "telegraf"
   client_id = "abc-def-ghj-klm"
   max_retry = 3

   ## Optional TLS Config
   sasl_username = "test"
   sasl_password = "test123"
   sasl_mechanism = "PLAIN"
   insecure_skip_verify = false
   data_format = "json"


[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = false

[[inputs.system]]

[[inputs.internal]]

有一个简单的方法,只需将“kafka.topic_suffix”配置添加到您的 output.kafka 设置中。之后你可以看到由telegraf similiar theese自动创建的新主题; telegraf_cpu, telegraf_system, telegraf_blabla.

 [[outputs.kafka]]
   brokers = ["127.0.0.1:9092","127.0.0.1:9093"]
   topic = "telegraf"
   client_id = "abc-def-ghj-klm"
   max_retry = 3

   ## Optional TLS Config
   sasl_username = "test"
   sasl_password = "test123"
   sasl_mechanism = "PLAIN"
   insecure_skip_verify = false
   data_format = "json"

   [outputs.kafka.topic_suffix]
     method = "measurement"
     separator = "_"