How to route Modbus Errors to Output Plugins?

I have a Telegraf configuration that gets input data from different Modbus devices using Input Modbus plugin and stores that data into InfluxDB using InfluxDB output plugin.

Is it possible to send specific metrics to InfluxDB when Modbus devices are returning errors?

For example, I have the following configuration:

interval = “5s”
tagexclude = [“type”, “name”, “host”, “slave_id”]
name = “NOT USED”
slave_id = 0
timeout = “3s”
controller = “tcp://”
holding_registers = [
{ name = “Item1”, byte_order = “ABCD”, data_type = “FIXED”, scale=0.001, address = [30121,30122]},
{ name = “Item2”, byte_order = “ABCD”, data_type = “FIXED”, scale=0.001, address = [30125,30126]},
plant = “Test Plant”
device=“Test Device”

When Modbus devices are not responding, I see the following rows in .log file:

2024-01-03T20:09:54Z E! [inputs.modbus] Error in plugin: dial tcp i/o timeout
2024-01-03T20:09:59Z E! [inputs.modbus] Error in plugin: dial tcp i/o timeout

I would like to have the information in InfluxDB that this particular metric is not available now due to i/o timeout, i.e. to send metric that has failing controller in config file (i.e. in this example) with all configured tags and just one special field (i.e. error) with error message. The same approach is expected for all other possible errors (i.e. Illegal data value etc.).

How to achieve that?

I have seen this feature request, but it is still open and no solution is suggested…

Here use case that I need is also described…

In short, no. Telegraf’s purpose is to generate metrics, not pass through errors as well. However, there is the internal plugin that will generate metrics about telegraf plugins and the errors they get. You could start to see that errors are generated; you only won’t know what the specific error is.

Thank you for your answer. Will look closer at


and its possibilities for my use case.

One more clarification - when ‘errors’ field of internal_gather measurement is cleared to zero?

Is it possible to clear it after successful reading of the metric by the input plugin? If yes, then it could be utilized to monitor current state of the particular input plugin (metrics are being obtained without errors or errors are present).

You can. But it is tricky

You can configure telegraf to save error logs, then you can use grafana’s log scrapping tool to send logs to a database.

I do not remember f it was promtail/loki?

But I am sure it is possible to route back to influxDB.

I did it because that exact reason. But the company I worked for went bankruptcy, so I lost acces of that project when got Laid-Off

Thank you for your reply. Will look into log parsing, because it looks like the only possible solution.

I am planning to use ‘inputs.tail’ plugin with ‘grok’ data format for getting modbus errors from telegraf.log