v-zhuravlev / libzbxmodbus

Loadable module to integrate Modbus (RTU, TCP and encapsulated) into Zabbix. Bulk data collection included.
https://share.zabbix.com/dir-libraries/zabbix-loadable-modules/modbus-loadable-module
GNU General Public License v2.0
50 stars 25 forks source link

Не могу заставить нормально работать. #15

Closed brutevinch closed 7 years ago

brutevinch commented 7 years ago

Происходит рандомно вот такая ерунда:

2017-06-02 12 21 08

Через несколько минут данные могут начать поступать, а другие (из этих трех) прекратить.

v-zhuravlev commented 7 years ago

Hi,

brutevinch commented 7 years ago

1) Modbus TCP 2) Zabbix 3.0 3) current Timeout is set to 10

v-zhuravlev commented 7 years ago
brutevinch commented 7 years ago
  1. selfmade modbus tcp -> modbus rtu gateway on esp8266 (OpenHab polling fine without any problems)
  2. last from master branch
brutevinch commented 7 years ago

Here is openhab config (maybe it can help you)

poll=30000 writemultipleregisters=true

tcp.sdm230_Voltage.connection=10.0.1.23:502:0 tcp.sdm230_Voltage.type=input tcp.sdm230_Voltage.valuetype=float32 tcp.sdm230_Voltage.length=2 tcp.sdm230_Voltage.start=0 tcp.sdm230_Voltage.id=1

tcp.sdm230_Current.connection=10.0.1.23:502:0 tcp.sdm230_Current.type=input tcp.sdm230_Current.valuetype=float32 tcp.sdm230_Current.length=2 tcp.sdm230_Current.start=6 tcp.sdm230_Current.id=1

tcp.sdm230_Power.connection=10.0.1.23:502:0 tcp.sdm230_Power.type=input tcp.sdm230_Power.valuetype=float32 tcp.sdm230_Power.length=2 tcp.sdm230_Power.start=12 tcp.sdm230_Power.id=1

v-zhuravlev commented 7 years ago

It might be related to resource locking (there is no for TCP).

Can you try the following patch https://github.com/v-zhuravlev/libzbxmodbus/tree/TCP-always-lock (with locking enabled for TCP as well)?

git clone -b TCP-always-lock --recursive https://github.com/v-zhuravlev/libzbxmodbus.git Run autogen.sh ./configure --prefix=/etc/zabbix --enable-zabbix-3 make make install

brutevinch commented 7 years ago

2017-06-02 15 28 42 Same thing =(

v-zhuravlev commented 7 years ago
  1. Ok, to 100% make sure it has nothing to do with resource sharing: In your Zabbix server (if it is possible to do so) please leave only single poller: StartPollers=1 and restart.

  2. can you also run ipcs -s while your Zabbix server with module loaded is runnning? and show me the output of it.

brutevinch commented 7 years ago
  1. done
  2. 2017-06-02 15 49 55

P.s. zbx agent working on same machine.

v-zhuravlev commented 7 years ago

Strange, accodring to this it looks like that you might be using old version (<0.6) of the module anyway. In the new version you must see zabbix semaphore with nsems = 128 and not 1.

Try deleting your old modules from (/usr/local/lib i suppose) and in zabbix server config point to the new location:

LoadModulePath = /etc/zabbix/lib

Restart server. Check that ipcs -s shows you the semaphore with nsems = 128. If not going to work, which linux distro do you use?

brutevinch commented 7 years ago

Here is with new module: 0x7a021f65 655365 zabbix 600 128

in zabbix 2 of 3 data sources are "Connection timed out"

/usr/src # cat /etc/debian_version
8.7

chroot debian for Synology

v-zhuravlev commented 7 years ago

even with single poller?

brutevinch commented 7 years ago

Ну если 1 поллер включается добавлением в конфиг сервера то да. Вот кусок конфига сервера: LoadModulePath = /etc/zabbix/lib LoadModule = libzbxmodbus.so Timeout = 10

StartPollers=1

v-zhuravlev commented 7 years ago

uff....weird.

Ok, lets try it again:

git clone -b debug_enabled --recursive https://github.com/v-zhuravlev/libzbxmodbus.git Run autogen.sh ./configure --prefix=/etc/zabbix --enable-zabbix-3 make make install

Then in configuration file:

LogType=console
DebugLevel=1

In zabbix frontend: Disable all modbus items and leave only one active.

Stop the zabbix-server rerun it with in the foreground: zabbix_server -f

You should now see all the modbus debug messages from the libmodbus lib. Please attach it here. They should contain a part where it fails also.

v-zhuravlev commented 7 years ago

You don't have any errors/timeouts with single item?

brutevinch commented 7 years ago

testing now. tell you later

v-zhuravlev commented 7 years ago

ok. If there are no issues with single item -> try reenabling them

brutevinch commented 7 years ago

with enabled 2 items:

Waiting for a confirmation...

<00><01><00><00><00><07><01><04><04><43><65><5A><85> Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][06][00][02] Waiting for a confirmation... <25><00><00><00><07><01><04><04><43><65><38> Invalid transaction ID received 0x25E3 (not 0x1) Connecting to 10.0.1.23:502 Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][00][00][02] Waiting for a confirmation... <00><01><00><00><00><07><01><04><04><43><63><3F><22>
brutevinch commented 7 years ago

here is with 3 items:

Waiting for a confirmation...

<00><01><00><00><00><07><01><04><04><41><78> Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][00][00][02] Waiting for a confirmation... <00><01><00><00><00><07><01><04><04><43><64> Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][06][00][02] Waiting for a confirmation... ERROR Connection timed out: select Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][0C][00][02] Waiting for a confirmation... <00><01><00><00><00><07><01><04><04><41><12><03> Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][00][00][02] Waiting for a confirmation... <00><01><00><00><00><07><01><04><04><43><61><01><00><00><00><07><01><04><04><43><69><62> Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][0C][00][02] Waiting for a confirmation... <00><01><00><00><00><07><01><04><04><41><58> Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][0C][00][02] Waiting for a confirmation... <26><63><00><00><00><07><01><04><04><43><6E><86> Invalid transaction ID received 0x2663 (not 0x1)
v-zhuravlev commented 7 years ago

Connecting to 10.0.1.23:502 Connecting to 10.0.1.23:502

It looks like that there is still more than one poller. Maybe do you have another StartPollers somewhere in the config file with not 1? try: in your debug_enabled repo: git pull make install new logging of zabbix_server -f now should provide pid of the process.

brutevinch commented 7 years ago

here is full config:

LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 LogType=console DebugLevel=1 PidFile=/var/run/zabbix/zabbix_server.pid DBName=zabbix DBUser=zabbix DBPassword=XXXX AlertScriptsPath=/usr/lib/zabbix/alertscripts ExternalScripts=/usr/lib/zabbix/externalscripts FpingLocation=/usr/bin/fping Fping6Location=/usr/bin/fping6 LogSlowQueries=3000

LoadModulePath = /etc/zabbix/lib LoadModule = libzbxmodbus.so Timeout = 10

StartPollers=1 AllowRoot = 1

Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][06][00][02] Waiting for a confirmation...

<00><01><00><00><00><07><01><04><04><3E><2F> pid:2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][0C][00][02] Waiting for a confirmation... ERROR Connection timed out: select pid:2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][00][00][02] Waiting for a confirmation... <00><01><00><00><00><07><01><04><04><43><5F><25>
v-zhuravlev commented 7 years ago

how did you implement Modbus TCP server? It this your own code?

brutevinch commented 7 years ago

2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][06][00][02] Waiting for a confirmation...

<00><01><00><00><00><07><01><04><04><3E><32><91> pid:2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][00][00][02] Waiting for a confirmation... <28><55><00><00><00><07><01><04><04><43><61><51> Invalid transaction ID received 0x2855 (not 0x1) pid:2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 pid:2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 pid:2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 pid:2247 hash:118 : 10.0.1.23 Unlocking pid:2247 hash:118 : 10.0.1.23 Locking Connecting to 10.0.1.23:502 [00][01][00][00][00][06][01][04][00][06][00][02] Waiting for a confirmation... <00><01><00><00><00><07><01><04><04><3E><30> pid:2247 hash:118 : 10.0.1.23 Unlocking
brutevinch commented 7 years ago

Here is gateway code

modbus_gate_v2.lua.zip

v-zhuravlev commented 7 years ago

selfmade modbus tcp -> modbus rtu gateway on esp8266 (OpenHab polling fine without any problems)

Could it be that OpenHab actually also sometimes receive invalid data/timeout? Just it doesn't show you that?

brutevinch commented 7 years ago

Saw openhab traces. There is no errors and warnings and all data received every 30 sec without any errors too. =(

brutevinch commented 7 years ago

Every 30 sec.

2017-06-03 0 09 21

v-zhuravlev commented 7 years ago

So let's sum ip what we have:

v-zhuravlev commented 7 years ago

try with disabled byte timeout:

in your debug_enabled repo: git pull make install

brutevinch commented 7 years ago

Hi, now I see some errors in openhab, please give some time to test it.

brutevinch commented 7 years ago

Sorry it was unstable buggy code.

v-zhuravlev commented 7 years ago

@brutevinch , Did you fix it? Is it working with libzbxmodbus now? With(debug branch) or without(current main branch) TCP locking?

brutevinch commented 7 years ago

Rewrite gateway code to mqtt.