# How to route Modbus Errors to Output Plugins?

**URL:** <https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705>\
**Category:** Telegraf\
**Tags:** modbus\
**Created:** [January 3, 2024, 8:26pm UTC](https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705 "2024-01-03T20:26:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebabeshko](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ebabeshko/32/14844_2.png) [@ebabeshko](https://community.influxdata.com/u/ebabeshko)\
**Post date:** [January 3, 2024, 8:26pm UTC](https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705/1 "2024-01-03T20:26:11Z")

</div>

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:

> [[inputs.modbus]]  
> interval = “5s”  
> name\_override=“ModbusDevice”  
> tagexclude = [“type”, “name”, “host”, “slave\_id”]  
> name = “NOT USED”  
> slave\_id = 0  
> timeout = “3s”  
> controller = “tcp://192.168.50.20:502”  
> 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]},   
> ]  
> [inputs.modbus.tags]  
> 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 192.168.50.20:502: i/o timeout  
> 2024-01-03T20:09:59Z E! [inputs.modbus] Error in plugin: dial tcp 192.168.50.20:502: 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. 192.168.50.20:502 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](https://github.com/influxdata/telegraf/issues/10245), but it is still open and no solution is suggested…

[Here](https://github.com/influxdata/telegraf/issues/11847) use case that I need is also described…

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [January 3, 2024, 9:44pm UTC](https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705/2 "2024-01-03T21:44:00Z")

</div>

> [@ebabeshko](#):
>
> Is it possible to send specific metrics to InfluxDB when Modbus devices are returning errors?

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.

---

<div class="post-metadata">

**Author:** ![ebabeshko](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ebabeshko/32/14844_2.png) [@ebabeshko](https://community.influxdata.com/u/ebabeshko)\
**Post date:** [January 4, 2024, 8:50pm UTC](https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705/3 "2024-01-04T20:50:43Z")

</div>

Thank you for your answer. Will look closer at

> [[inputs.internal]]

and its possibilities for my use case.

---

<div class="post-metadata">

**Author:** ![ebabeshko](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ebabeshko/32/14844_2.png) [@ebabeshko](https://community.influxdata.com/u/ebabeshko)\
**Post date:** [January 4, 2024, 9:40pm UTC](https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705/4 "2024-01-04T21:40:00Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![fercasjr](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@fercasjr](https://community.influxdata.com/u/fercasjr)\
**Post date:** [January 9, 2024, 12:33pm UTC](https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705/5 "2024-01-09T12:33:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ebabeshko](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ebabeshko/32/14844_2.png) [@ebabeshko](https://community.influxdata.com/u/ebabeshko)\
**Post date:** [January 9, 2024, 7:17pm UTC](https://community.influxdata.com/t/how-to-route-modbus-errors-to-output-plugins/32705/6 "2024-01-09T19:17:34Z")

</div>

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
