count bytes with influxs telegraf

167 Views Asked by At

I can receive messages with the inputs.mqtt_consumer telegraf plugin, but it gives me a lot of data in influxdb.

How can I in the telegraf configuration just count the number of received bytes and messages and report that to influx db?

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

[[outputs.influxdb_v2]]
  urls = ["XXXXXXXXXXXXXXXX"]
  token = "$INFLUX_TOKEN"
  organization = "XXXXXXXXXXXXXXX"
  bucket = "XXXXXXXXXXXXXXX"

[[inputs.mqtt_consumer]]
  servers = ["tcp://XXXXXXXXXXXXXXXXXXXXX:1883"]
  topics = [
    "#",
  ]
  data_format = "value"
  data_type = "string"

I tried to google around but din't find any clear ways to do it.

I just want number of bytes and messages received each minute for the selected topic

1

There are 1 best solutions below

0
On

I did not manage to receive all the messages and count them, but I found a solution where I can get the data from the broker. Not exactly what I asked for but fine for what I need.

  topics = [
    "$SYS/broker/load/messages/received/1min",
    "$SYS/broker/load/messages/sent/1min",
  ]
  ...
  data_format = "value"
  data_type = "float"