Hi, yes I read that, that’s a nice example, but the child elements use the same name, but in my case the child element name is incremented by +1.
Before asking this question, I tried your suggestion (add such lines under original) and telegraf reject it with below message
[telegraf] Error running agent: Error loading config file C:\Program Files\InfluxData\telegraf.conf: Error parsing data: line 247: table inputs.http.xml.fields is in conflict with table in line 243
It sounds like you want to have one metric for root/ch1 and another metric for root/ch2. When you need a metric per xml node like this, you need to use the metric_selection setting of telegraf’s xml parser. telegraf/README.md at master · influxdata/telegraf · GitHub
Here’s an example I got working with your data. I’ve switched to a file input instead of http, but that’s not important.
[[inputs.file]]
name_override = "thermometer"
files = ["community-24806.xml"]
data_format = "xml"
[[inputs.file.xml]]
metric_selection = "/root/ch1|/root/ch2"
# metric_selection = "/root/*[starts-with(name(),'ch')]" # or if you want all nodes starting with ch
timestamp = "root/timeunix"
[inputs.file.xml.tags]
channel = "substring-after(name(), 'ch')"
sensor = "name"
[inputs.file.xml.fields_int]
alarm = "number(alarm)"
[inputs.file.xml.fields]
# sensor = "string(name)" # this is now a tag
value = "number(aval)"
unit = "string(unit)"
Hi @reimda
Thanks for the support, I didn’t know xpath could be used.
Just a small problem, I still want to store the devname in the db, but now it seems that metric_selection has removed this information. How to solve it ?
Hi @reimda,
as workaround I was trying reconfig device and rename sensor name to include also devname.
But there is a string length limitation, so now I have no way to identify the device.
if you want to store devname as a tag in your example, just specify an absolute path (outside of the selected metric) by adding devname = "/root/devname" to your [inputs.file.xml.tags] section. Similar is possible for fields…
Hi @srebhan, yes, it works! Originaly I used devname = "string(/root/devname)" and after I was advised to use metric_selection, it stopped working. Then I played around with it in many ways, not sure why string() can’t be used for tag selection when it can be used for field selection. I can’t believe it’s that simple
I think string() should neither work for field_selection nor for tag_selection as the selection needs to be a node. Anyway, for tags the target-type is clear (string), furthermore, the default-type in XML is string, so you should omit that anyway.