-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XPath parser extension to allow parsing of JSON, MessagePack and Protocol-buffers #9277
Conversation
Please note, the documentation is not yet updated. This is by intention and will be fixed after a first round of reviews. |
Is this extension ready to test with Sparkplug B messages? I have time available to give it a good try. |
@mtnguru thanks for the offer. If you point me to the protocol-buffer of "Sparkplug B messages" I can add it so you can give it a try... |
Here is a link to the cirrus github page - https://github.com/Cirrus-Link/Sparkplug/tree/master/sparkplug_b Sparkplug B is used in the Groov EPIC controller |
9e07046
to
a336d4f
Compare
Hey @mtnguru. I added sparkplug_b for parsing. It was a bit more difficult that expected as I had to first create a golang implementation of the protobuf @https://github.com/eclipse/tahu, which seems to be the new location of the project. I used the following config for parsing a "device birth" dummy message [[inputs.file]]
files = ["./tahu_msg.dat"]
data_format = "protobuf"
xpath_protobuf_type = "org.eclipse.tahu.protobuf.Payload"
[[inputs.file.protobuf]]
metric_selection = "metrics[not(template_value)]"
metric_name = "concat('tahu_', substring-after(name, ' '))"
timestamp = "timestamp"
timestamp_format = "unix_ms"
[inputs.file.protobuf.tags]
name = "substring-after(name, ' ')"
[inputs.file.protobuf.fields_int]
type = "datatype"
[inputs.file.protobuf.fields]
value = "(int_value | long_value | float_value | double_value | boolean_value | string_value)"
[[inputs.file.protobuf]]
metric_selection = "metrics/template_value/metrics"
metric_name = "concat('tahu_', name)"
timestamp = "timestamp"
timestamp_format = "unix_ms"
[inputs.file.protobuf.tags]
name = "substring-after(name, ' ')"
[inputs.file.protobuf.fields_int]
type = "datatype"
[inputs.file.protobuf.fields]
value = "(int_value | long_value | float_value | double_value | boolean_value | string_value)" and got
|
a336d4f
to
e496f5e
Compare
@mtnguru you can use the artifacts pubished by the tigerbot in the comment above. Please let me know if this works for you or in case you find any issues. |
Hello Sven, I'm very new to telegraf and go - However I can now compile telegraf and am starting to learn how to debug it. There's still a lot to learn. A couple questions: I'm trying to duplicate what you did - Where did you find the ./tahu_msg.dat file? I'm using the mqtt_consumer input plugin instead of 'file'. Can I take your configuration file and replace the word 'file' with 'mqtt_consumer' and it will possibly work? I see an issue that the topic is not encoded with protobuf, only the payload is. Therefore they have to be recombined on output. Thanks for looking at this, it's critical for my project and most of my focus right now. This is by far the best solution I've found. James Sorensen |
@mtnguru you can use the artifacts the tiger-bot creates for for you by clicking on the small black triangle in the comment here. No need to build telegraf yourself...
I created some dummy data using the python protocol buffer implementation with this script placed in
Yeah kind of. You should use and configure theMQTT plugin to get the raw protobuf data. Then you use this part for parsing: data_format = "protobuf"
xpath_protobuf_type = "org.eclipse.tahu.protobuf.Payload"
[[inputs.mqtt_consumer.protobuf]]
metric_selection = "metrics[not(template_value)]"
metric_name = "concat('tahu_', substring-after(name, ' '))"
timestamp = "timestamp"
timestamp_format = "unix_ms"
[inputs.file.protobuf.tags]
name = "substring-after(name, ' ')"
[inputs.mqtt_consumer.protobuf.fields_int]
type = "datatype"
[inputs.mqtt_consumer.protobuf.fields]
value = "(int_value | long_value | float_value | double_value | boolean_value | string_value)"
[[inputs.mqtt_consumer.protobuf.protobuf]]
metric_selection = "metrics/template_value/metrics"
metric_name = "concat('tahu_', name)"
timestamp = "timestamp"
timestamp_format = "unix_ms"
[inputs.mqtt_consumer.protobuf.protobuf.tags]
name = "substring-after(name, ' ')"
[inputs.mqtt_consumer.protobuf.fields_int]
type = "datatype"
[inputs.mqtt_consumer.protobuf.fields]
value = "(int_value | long_value | float_value | double_value | boolean_value | string_value)" . |
Success! almost...... The protobuf parser is working with the mqtt_consumer plugin. However the Sparkplug specification makes it so MQTT packets are not atomic. The DBIRTH packet lists all the metric names and associates them with a numeric alias. Subsequent DDATA packets contain the numeric alias and do not have the full topic name. Therefore the input plugin has to save the names and their alias when they receive the DBIRTH packet, Upon receipt of a DDATA the alias is looked up and the associated name is appended the topic. The next 2 comments are examples of the DBIRTH and DDATA packets. Here is the test output I'm getting from telegraf --test --debug 2021-06-15T14:51:05Z D! [parsers.protobuf::mqtt_consumer] XML document equivalent: "1716237686651029<is_null>false</is_null>Quality3<int_value>600</int_value><float_value>5401.963</float_value>1816237686651029<is_null>false</is_null>Quality3<int_value>600</int_value><float_value>23.298462</float_value>16237686651029<is_null>false</is_null>3<int_value>600</int_value>Quality<float_value>5401.963</float_value>19311623768665102"
|
@mtnguru, the input plugin should not be bothered with this kind of "smart" :-/ behavior. What you can do is to use the If you don't mind, please contact me on slack, so we can work out the starlark part and add your use-case it as an example. |
Example of the DBIRTH packet - some unused metrics have been deleted to shorten the output |
Example of the DDATA packet { |
Hello @shantanoo-desai, I welcome your help, we're very close to success. @srebhan and I talked yesterday and he created a Starlark program to save the aliases in DBIRTH packets and use that to resolve the name in the DDATA packets. I'm working today to get that working. Are you familiar with starlark. Where are your sparkplug packets coming from, do you have a device like the Groov EPIC? James |
@mtnguru I was thinking more for setting up some dummy example from the eclipse-tahu repo and running it through a mosquitto broker instance on my machine. I could then probably spin up telegraf to achieve the acquisition into InfluxDB. I already have a stack ready tiguitto where I can play around with the configuration. As for starklark, no really happen to apply it as of now but seems like it might do the tricks for |
@shantanoo-desai, @mtnguru and myself worked out a nice starlark script to convert the raw values into a nice metric. I think @mtnguru is currently polishing the script and adds some bells and whistles but he will likely publish that script as a PR or so. |
@shantanoo-desa, @srebhan - We have the code working to load data - yay! |
@mtnguru as this is not my day-job, I currently cannot afford spending the time in meetings. Please feel free to post the code here, open a separate issue or drop me a note on slack and I will try to give feedback ASAP. Sorry! |
e496f5e
to
9b90456
Compare
…a temporary workaround until merged upstream.
… case looking up the user-specified value failed.
… external XPath tester.
…s is a temporary workaround until merged upstream.
…t output flooding in debug.
451ecaa
to
a7fd685
Compare
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
@mtnguru , @srebhan
When I load this config with Telegraf v1.19.1, I get following error (also when replacing xpath_protobuf with protobuf) so I guess I am missing a configuration step or perhaps a specific version, can you please point me in the right direction?
Just for reference an example of the test data I am processing (as protobuf):
Many thanks for your feedback! |
@linkdat this parser is only available in the "master" branch and not yet released as a version. You can use a nightly build or build telegraf from git. |
@srebhan , Thank you for the swift reply! |
Hi all, thanks for implementing sparkplug b, it is very much appreciated! I just tested the nightly build, and I get an error as soon as an mqtt message comes in:
My telegraf.conf:
Any ideas? |
@martinscheffler can you please open an issue for your problem (remember to redact tokens and credentials ;-)) and report what kind of raw data you receive by setting |
Hi guys, I'm a late comer to this thread and am trying to get exactly this working on my setup. I have tried using the config from @srebhan above but am getting an error loading the config saying inputs.mqtt_consumer.protobuf.fields_init on line 61 conflicts with line 49 and have no clue why.. My config is
Just wondering if anyone can point me in the right direction please? I think I already see a major problem.. this is now xpath_protobuf not protobuf by the looks of the docs... The docs also say
Where would I find a .proto files for SparkplugB (if one exists) and how do I use it if it does? Has anyone managed to get this working? Ta |
resolves #9075
related to #9197 and PR #9246
This PR renames the
xml
-parser toxpath
and massively extend the functionality. Current configurations usingxml
will still work, while it is now possible to also parse JSON files using the XPath-syntax.Additionally, we can generically parse msgpack data using the XPath-syntax without adding anything at compile-time.
Furthermore, we can now generically parse protocol-buffer data also using the XPath-syntax. To do so, in most cases the only required step is to import the protocolbuffer in the
protocolbuffer_document.go
file.Some short test-cases are added to demonstrate the functionality.