I am not very well versed in Telegraf, but am using NodeRED to grab Modbus RTU data, format it, and then send to Influx. Is there any reason you are not going that route?
Hey @grant1, I have a flow in Node-RED to do this but I think parsing the data adds complexity. I’ve used Telegraf for Modbus TCP and it make’s it very simple.
Assuming there is a problem with controller = "file:///dev/ttyUSB0" but not 100% sure. Will try from a different distro to see if the problem is repeatable.
@Duncan For my own understanding (and bearing in mind I have only configured a .conf file for Telegraf once on a Raspberry Pi to grab the CPU, RAM, board temperature, etc.), where do you place your .conf file? Let’s say the Modbus RTU device is viewable through your network somewhere (e.g. connected via a USB-to-RS485 dongle connected to a PC on the LAN). How does the .conf file know where to “see” the Modbus data?
@grant1 .conf file is the default located in /etc/telegraf and Modbus RTU is a serial connection so you have to specify the usb port you are using to read the Modbus device from. In this case - file:///dev/ttyUSB0
Hey, that image is correct. Telegraf is installed on the Raspberry Pi (could be any hardware able to run Telegraf). Then a USB to RS485 cable is plugged from the USB port on the Raspberry Pi to the Modbus terminals on the device you want to read from. In my case an electrical meter. And yes, the file location is /etc/telegraf by default when installing Telegraf.
OK, got it. I have always used Node-RED on the Pi (or whatever is connected to the Modbus device) and had very good success using that method, but am always willing to learn new methods.
I am wondering if its a permissions issue since the telegraf service uses the telegraf user to read from the Modbus RS485. To test this theory @Duncan could you run telegraf --debug --config /foo/telegraf.conf
It works fine. I can see activity on the RS485 cable. Modbus readings on the debug output and it’s saving to InfluxDB Cloud. Once I exit those commands and run…
systemctl status telegraf
This is the output…
● telegraf.service - Telegraf
Loaded: loaded (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-02-20 14:51:23 SAST; 55min ago
Docs: https://github.com/influxdata/telegraf
Main PID: 3891 (telegraf)
Tasks: 9 (limit: 407)
CPU: 10.383s
CGroup: /system.slice/telegraf.service
└─3891 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d
Feb 20 15:46:10 raspberrypi telegraf[3891]: 2023-02-20T13:46:10Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:13 raspberrypi telegraf[3891]: 2023-02-20T13:46:13Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:20 raspberrypi telegraf[3891]: 2023-02-20T13:46:20Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:23 raspberrypi telegraf[3891]: 2023-02-20T13:46:23Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:30 raspberrypi telegraf[3891]: 2023-02-20T13:46:30Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:33 raspberrypi telegraf[3891]: 2023-02-20T13:46:33Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:40 raspberrypi telegraf[3891]: 2023-02-20T13:46:40Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:43 raspberrypi telegraf[3891]: 2023-02-20T13:46:43Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:50 raspberrypi telegraf[3891]: 2023-02-20T13:46:50Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:53 raspberrypi telegraf[3891]: 2023-02-20T13:46:53Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
So assume I’m doing something wrong or there is a bug?
@Duncan which user is used in the systemd service to start Telegraf? Is it the same as you use on the console with telegraf --config telegraf.conf --test --debug?
pre-condition: Telegraf was installed via dnf install telegraf. Then I put files in /etc/telegraf/telegraf.d/ and edited them to fit my needs.
I got the same permission denied errors as mentioned above.
It turns out, that on my system the user telegraf is running the service unit telegraf.service
# Display the user that is running the service "telegraf"
$: systemctl show -pUser telegraf.service
User=telegraf
# Add that user to the dialout group to give permission
$: sudo usermod -aG dialout telegraf