Re: [collectd] Modbus segfault
Hi, On Fri, May 04, 2012 at 11:23:42AM +0200, colle...@faxm0dem.org wrote: Attached patch solves this (to be applied agains stefan's fork). Stefan: can you add it to your github, then issue a pull request? Attachement didn't make it. Here's the fork: https://github.com/faxm0dem/collectd/tree/faxm0dem/modbus Cheers, ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Modbus segfault
Hi, On Wed, Feb 01, 2012 at 02:16:58PM +1030, Matt Baker wrote: Hi Stefan, I thought I would give your modified modbus.c file a try. It worked fine for awhile, but then it started reporting: [2012-02-01 14:00:47] plugin_read_thread: Handling `modbus-10.1.2.2'. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. Looking at the code (and i'm not a C programmer), I was wondering if you thought it would be good idea if the code was changed so if it hit this sort of failure it tries to reestablish the host connection again using a mb_init_connection? Attached patch solves this (to be applied agains stefan's fork). Stefan: can you add it to your github, then issue a pull request? Cheers, ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Modbus segfault
Hi, On Tue, Apr 10, 2012 at 04:02:53PM +0200, colle...@faxm0dem.org wrote: Just to check in with you guys having the issue. I am having the exact same behaviour on a RHEL5 host, and Stefan's patch solved the connection segfault. I will test the patched plugin for some time and report back. After a week of data collection I can say this plugin is not stable. It works well when starting collectd, but eventually fails with the following message: Modbus plugin: modbus_read_registers (w.x.y.z) failed. Giving up. The message is repeated endlessly, and only restarting collectd helps. ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Modbus segfault
Hi, On Thu, Jan 19, 2012 at 03:36:45PM +0100, Stefan Nickl wrote: I also stumbled across the modbus segfault (collectd 5.0.1 / libmodbus 3.0.1 / gentoo, both i386 x86_64). Just to check in with you guys having the issue. I am having the exact same behaviour on a RHEL5 host, and Stefan's patch solved the connection segfault. I will test the patched plugin for some time and report back. I suggest you post a pull request on github so the fix gets included in master. Cheers ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Modbus segfault
Hi Stefan, I too found that it must have been an intermittent connection issue so I started to look at the code. I went back to the original modbus.c file from the 3.0.2 distribution and found that there is currently a for loop which does the connection (I am not a C programmer), but this loop when it exits doesn't check if the connection actually did occur. Instead it just falls into assuming the connection is all okay. So at the end of the for loop I added the following check: if (status == 0) { DEBUG (Modbus plugin: connection issue, giving up!); modbus_close (host-connection); modbus_free (host-connection); host-connection = NULL; return (-1); } And this appears to work. It still occasionally has the timeout issue, but it at least then continues and retry's the connection then next time around. I have been running this now for the past 3-4 days and everything is working well. I will now need to try to resolve the timeout problem, maybe increasing the timeout value might help. Regards, Matt Hi Matt, on my side collectd worked apparently perfect (with debug, in foreground) since my last mail. But I just pulled the Ethernet plug on my PLC for a bit and the collectd side does not recover - looking similar to what you sent - so that's a start :) My idea is that since collectd calls the plugin repeatedly anyways to just check whether there is a connection (the getpeername() trick is something I found on the net, not sure about caveats), if not try to establish one and then give it a single try. Hope to find some time soon to look into this, Stefan ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
Re: [collectd] Modbus segfault
Hi Stefan, I thought I would give your modified modbus.c file a try. It worked fine for awhile, but then it started reporting: [2012-02-01 14:00:47] plugin_read_thread: Handling `modbus-10.1.2.2'. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. [2012-02-01 14:00:47] Modbus plugin: modbus_read_registers (10.1.2.2) failed. Giving up. Looking at the code (and i'm not a C programmer), I was wondering if you thought it would be good idea if the code was changed so if it hit this sort of failure it tries to reestablish the host connection again using a mb_init_connection? Cheers, Matt Hi Matt, by now I'm running a somewhat more changed version that I put up at https://github.com/snickl/collectd/tree/snickl/3-modbus-connect-handling (my first attempt on github btw). I also noticed that data stopped coming in after several hours, but from the logs it looked more like modbus connection errors. Debug is enabled now, but no problem for over a day. I'll sure check on zero values if it stalls again. Cheers, Stefan ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
[collectd] Modbus segfault
Hi all, I also stumbled across the modbus segfault (collectd 5.0.1 / libmodbus 3.0.1 / gentoo, both i386 x86_64). The problem is that host-connection is simply never initialized in mb_read_data() before being passed to libmodbus. The only place mb_init_connection() is called is from within the reconnection loop below. Adding this before the call to modbus_set_slave() makes the crash go away: if (host-connection == NULL) { status = mb_init_connection (host); if (status != 0) { ERROR (Modbus plugin: mb_init_connection (%s/%s) failed. , host-host, host-node); return (-1); } } As I'm reading float values I also had to modify mb_register_to_float() to get what I was expecting. But not sure whether this is due to running on a 64bit machine or just my PLC being backwards. What I'm doing is static float mb_register_to_float (uint16_t hi, uint16_t lo) /* {{{ */ { union { uint8_t b[4]; uint16_t s[2]; float f; } conv; #if BYTE_ORDER == LITTLE_ENDIAN conv.s[0] = hi; conv.s[1] = lo; #else ... -- Cheers, Stefan ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd
[collectd] Modbus segfault
Hi, I am trying to get collectd working with the modbus plugin but I am getting a segfault each time collectd runs: Dec 16 01:20:55 vmunix: [1074386.330565] collectd[29149]: segfault at 20 ip b7e03bcc sp b6fa1270 error 4 in libmodbus.so.4.0.0[b7e02000+6000] Using Collectd version 5.0.1 with libmodbus 2.9.2 (have also tried 2.9.4 3.0.1). Running ldd on the modbus.so looks like it is picking up the libmodbus correctly: # ldd modbus.so linux-gate.so.1 = (0xe000) libmodbus.so.4 = /usr/lib/libmodbus.so.4 (0xb7ee1000) libdl.so.2 = /lib/libdl.so.2 (0xb7edd000) libc.so.6 = /lib/libc.so.6 (0xb7d9f000) /lib/ld-linux.so.2 (0xb7ef4000) Config for the plugin in the collectd.conf file is just a minor modification of the documented example: Plugin modbus Data voltage-input-1 RegisterBase 0 RegisterType float Type voltage Instance input-1 /Data Data voltage-input-2 RegisterBase 2 RegisterType float Type voltage Instance input-2 /Data Host 10.1.2.2 Address 10.1.2.2 Slave 1 Instance power-supply Collect voltage-input-1 /Slave /Host /Plugin Just wondering if anyone has managed to get modbus support working with the latest version? Matt ___ collectd mailing list collectd@verplant.org http://mailman.verplant.org/listinfo/collectd