influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.5k stars 5.55k forks source link

add conversion mechanism to modbus - similar to snmp plugin #7266

Closed orbweaver closed 3 years ago

orbweaver commented 4 years ago

Feature Request

add conversion mechanism to modbus - similar to snmp

Opening a feature request kicks off a discussion.

Proposal:

add a conversion/scaling feature to modbus data

Current behavior:

some modbus devices keep an integer value in their registers that are a multiple of the actual value i.e. "563" in the register represents an actual value of "56.3"

Desired behavior:

use a conversion factor, similar to the snmp input plugin. sample from snmp pasted below

Apply one of the following conversions to the variable value:

##   float(X) Convert the input value into a float and divides by the
##            Xth power of 10. Effectively just moves the decimal left
##            X places. For example a value of `123` with `float(2)`
##            will result in `1.23`.
##   float:   Convert the value into a float with no adjustment. Same
##            as `float(0)`.
##   int:     Convert the value into an integer.
##   hwaddr:  Convert the value to a MAC address.
##   ipaddr:  Convert the value to an IP address.
# conversion = ""

Use case:

when collecting from diverse data sources (snmp, modbus, exec scripts,etc) it would be beneficial to have the data uniformly formatted and scaled when storing them, to help simplify

danielnelson commented 4 years ago

There is support for scaling values, check out the scale option when defining the registers.

orbweaver commented 4 years ago

that scaling seems to work on FLOAT32 just fine, but the device stores data in INT16 registers, and when I try to use the scale option on an INT16, it simply truncates the last digit, i.e. "842" becomes "84" instead of "84.2"

danielnelson commented 4 years ago

I think this is a bug.

danielnelson commented 4 years ago

I thought this was due to an issue with scaling, but this is because we are reporting this value as an integer since it was loaded as an integer, and of course integers don't have a factional part.

srebhan commented 3 years ago

@orbweaver did you check the scaling-factor lately? I think it should work just fine if you specify INT16 and 0.1 as scaling factor. Otherwise, as Daniel said, it's a bug. The problem with your suggestion is that devices with scaling factors such as 200.0 or 0.2 or 0.128 won't be supported and we definitively have those...

orbweaver commented 3 years ago

Thanks for the update. I will be able to test next week and report back. Cheers.

srebhan commented 3 years ago

@orbweaver any news?

orbweaver commented 3 years ago

OK I downloaded the latest and gave it a try. Still doesn't seem to have the desired effect. Pasted details below:

According to the PLC documentation, I need to move the decimal point to the left for the register containing "Total Power Factor" I started with this in the configuration: { name = "Total Power Factor", byte_order = "AB", data_type = "INT16", scale=1.0, address = [1048]},

and then ran a test:

telegraf --config pdp.test.conf --test 2021-02-18T18:31:31Z I! Starting Telegraf 1.17.2 pdp_modbus,datasource=pdp,host=scada-mon.local.net,name=pdp,type=holding_register Total\ Power\ Factor=89i 1613673091000000000

...and then I changed the scale setting to 0.1 to see what happens:

{ name = "Total Power Factor", byte_order = "AB", data_type = "INT16", scale=0.1, address = [1048]},

and the test output truncates a digit instead of introducing a decimal point:

telegraf --config pdp.test.conf --test 2021-02-18T18:32:18Z I! Starting Telegraf 1.17.2 pdp_modbus,datasource=pdp,host=scada-mon.local.net,name=pdp,type=holding_register Total\ Power\ Factor=8i 1613673139000000000

srebhan commented 3 years ago

Ok I see the problem now. If you specify INT16 you always get an int16 also after scaling. Try FIXED as data_type this should do what you expect.

orbweaver commented 3 years ago

That did the trick. Thank you so much!

On 2021-02-22 08:37, Sven Rebhan wrote:

Ok I see the problem now. If you specify INT16 you always get an int16 also after scaling. Try FIXED as data_type this should do what you expect.

-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [1], or unsubscribe [2].

Links:

[1] https://github.com/influxdata/telegraf/issues/7266#issuecomment-783461771 [2] https://github.com/notifications/unsubscribe-auth/AEXHY4DPI5GFXJWDZ4YRFSDTAJ23XANCNFSM4LZU4VBQ

srebhan commented 3 years ago

@orbweaver cool. I'm closing the issue then...

gnoto commented 2 years ago

Hi, I have the same problem but I can't resolve with data_tye = FIXED. I receive this error:

2022-02-05T11:38:24Z E! [outputs.influxdb_v2] Failed to write metric (will be dropped: 422 Unprocessable Entity): unprocessable entity: failure writing points to database: partial write: field type conflict: input field "Temp B1" on measurement "modbus" is type float, already exists as type integer dropped=1

Any idea? tnx a lot

srebhan commented 2 years ago

@gnoto I answered your comment on #10592, please continue the matter there.