Telegraf interval varies too much with modbus inputs to influxdb

42 Views Asked by At

I am reading data from a modbus device with telegraf plugin and I would like "as close as it can get" interval of 500ms. Telegraf plugin writes inputs to influxdb.

Am I having a wrong tool or am I not using it correctly? It does not seem to mater too much if I read one or several registers.

[global_tags]
[agent]
  interval = "500ms"
  round_interval = false
  metric_batch_size = 100
  metric_buffer_limit = 1000
  collection_jitter = "0s"
  collection_offset = "500ms"
  flush_interval = "1s"
  flush_jitter = "0s"
  precision = "1ms"
  debug = true
  logfile = "loki.txt"

[[outputs.influxdb_v2]]
   urls = ["http://127.0.0.1:8086"]
   token = "atoken"
   organization = "org"
   bucket = "modbus"

 [[inputs.modbus]]

   name = "Device"
   slave_id = 1
   timeout = "1s"
 busy_retries_wait = "100ms"

   controller = "tcp://192.168.1.103:8899"

transmission_mode = "TCP"

    configuration_type = "request"
    optimization = "max_insert"

 optimization_max_register_fill = 100

  [[inputs.modbus.request]]

    slave_id = 1
    byte_order = "CDAB"
    register = "holding"
    fields = [

      { address=82, name="energy",        type="FLOAT32",   scale=1.0},
      
      ]

    [inputs.modbus.request.tags]
      group = "energy_group"
      

This is what I get:

output from influxdb

1

There are 1 best solutions below

2
On

Reason

Telegraf runs as a single process to poll each of it's available plugins, if any plugin fails or delays, it interrupts the rest plugins. That is why you see those interval varies especially when you run with multiple plugins.

Solution 1 - Run a dedicated telegraf for each Modbus bus

As the official best practice document recommended, you can run multiple telegraf instances.

Solution 2 - Use Modbus-to-MQTT gateway (Recommended)

Modbus is master-slave architecture, which is slow and usually blocking communication, while MQTT is event-based and lightweight, now becomes a very popular protocol to integrate with modern IoT systems, see here for a detail comparision. Use a tool like modpoll, you can easily forward Modbus data to MQTT broker and use MQTT Consumer Input Plugin to integrate with telegraf.