Conversation
Remove the modbus exporter meta-metrics that duplicate data from the scrape information. In order to differentiate between different failures, use http status codes instead. Signed-off-by: Ben Kochie <superq@gmail.com>
Trying to help other people dodge some of the hurdles I stumbled over
…port tested, but I might have broken TCP support in the process
…king Modbus over RS485. Not all registers are included, but the important ones are.
|
@bastischubert any chance you can test if TCP support still works with this patch? I only have RS485 devices here with me. @RichiH said on IRC that you might be able to help :) |
|
I'll test on monday when i'm back from vacation |
|
You can use https://github.com/3cky/mbusd as a serial to RTU converter, I have been using it for a while to use modbus_exporter with a cheap USB RS-485 adapter. Thank you for working on serial support! |
…king Modbus over RS485. Not all registers are included, but the important ones are.
SuperQ
left a comment
There was a problem hiding this comment.
Some minor nits, otherwise seems sane.
…move stray newline
|
This functionality is broken when using more than one subtarget on the same target. The problem is that serial communication is, well, serial, and prometheus might scrape two targets simultaneously, confusing the modbus code. I haven't had any luck figuring out how to make sure only one thing happens at a time on the rs485 serial bus. Does anyone have input on how to achieve this? I was hoping Any input would be appreciated. Otherwise I will sadly have to close the PR since I have no idea how to fix it. |
|
@SuperQ can you help with making certain that sequentiality is ensured? Does this appear per target only or would we hit the same with a lot of different targets at once? Global locks or sequencing is meh. If we end up in that situation, we would need to emit some metrics around this. |
|
The issue is only per serial bus/device (for example /dev/ttyUSB0). The serial device is called A lot of different targets at once is fine (as in, different serial devices When using relabelling the targets in prometheus.yml become sub_targets in modbus_exporter, so it is a bit confusing. But I think the above should be clear, see also the log snippet in the next comment :) |
|
This log snippet shows the issue - all INFO[109961] got scrape request for module 'carlo_gavazzi_em_et_3xx_series' target '/dev/ttyUSB0' and sub_target '5' source="modbus_exporter.go:130" |
… emet3xx_, change serial speed to 57600, and remove some metrics which are configuration, not measurements
… error, only mutex lock for serial scrapes, and track some metrics around mutex locking
…fix a few copypaste and variable naming errors
|
OK, after a bit of fiddling this actually works really well now. I had to update the goburrow/modbus dependency because I hit an old bug they fixed since then. I solved the sequentiality requrement by wrapping the scrape in a mutex for serial scrapes. This means if one thread is already using the serial bus another thread will have to wait. I've added two new metrics to track the mutex stuff, a counter to total how many seconds are spent waiting for a mutex lock, and a gauge to show how many are waiting right now. This leave one open issue, I don't have a system with two serial busses right now, but the mutex should be serial bus specific (there is no need to make a scrape on serial bus /dev/ttyUSB1 wait for /dev/ttyUSB0 to finish). Before I dig into solving that (I do not have any systems with multiple serial adapters attached to seperate rs485 busses handy to test) I would like to request a review to make sure what I have now will be accepted when I finish the PR. Maybe @SuperQ can take another look? Thanks! |
… are any, and readd scrape request logline removed by mistake
…og message when serial port is busy
…targets require retrying
|
Hi, thanks for this feature! It successfully retrieves the metric only if SINGLE metric is defined in modbus.yml. If I add one more metric, i'm getting a bunch of various errors, such as, timeout, CRC error or that another device (id=4) responded instead of actual one with sub_module=32. It looks to me that two requests are sent to serial port at the same time and so collision happens? Maybe I'm wrong. Like so: HW setup should be fine, since, I can poll multiple metrics using zabbix https://github.com/v-zhuravlev/libzbxmodbus and also I can get data using modpoll utility. Sample request I'm using: |
|
sounds like you might be scraping faster than your serial bus or devices can keep up, how often are you scraping and how long does a scrape take and how many targets do you have? remember, a serial bus is serial :) I haven't forgotten about this patch and I will get back to it soon, I am currently pressed for time |
… error, only mutex lock for serial scrapes, and track some metrics around mutex locking
…fix a few copypaste and variable naming errors
… are any, and readd scrape request logline removed by mistake
…og message when serial port is busy
…targets require retrying
…ecase is when using these meters through a modbus RTU to modbus TCP gateway/proxy
… mutex to the mutexmap
…match the _tcp module
…rter into readd_serial_support
…te registers is used for the integer and decimal parts of the register, add cagaemet_consumed_precision_kwh_total metric using this type of register in modbus.yml
|
(Just to track this, I keep clicking the "Approve and Run" on the tests) @tykling what's the status on your end? Does serial work in production? @bastischubert do you currently have hardware to test TCP against? |
|
Hmm, in this round of tests, even more fail than the last round. See above for details, @tykling |
|
hey :) Yes, serial works in production, even with multiple serial ports (without parallel scrapes messing anything up). I am very happy with it actually. I also tested TCP a while back and it works well. But this PR is a mess. I fucked up a merge a while back so the branch has weird history with a bunch of commits that are not relevant. I have been meaning to close it and open a new "fresh" PR. I also have a bunch of questions about the PR and the general direction you want to take with the project.
I think back ages ago when I first forked this there was not much in the way of tests so I haven't written any. But I will take a look at the failing tests and see what I can do. I am not very experienced with Go, this has been my very first real adventure with it in fact :) |
|
Nice to hear it's working in prod! Feel free to open a new PR, or clean up locally and force-push into this one. Both works. Yes, we want to collect more default configs, but there's not a huge inrush of configs... Feel invited to add everything you have. Modbus has a lot of weird warts -- As long as there's a sane way to express those quirks in declarative configuration, I'd err on the side of supporting the weird stuff. Any help with the tests, or new tests, appreciated. This is more a work of love and passion by a bunch of people without the hardware to actually test the software, so every bit helps. |
As discussed on IRC. Work in progress, warning: TCP untested.
The PR also adds config for a couple of electricity meters I've been testing with, Carlo Gavazzi EM111 and EM340.