Filter all "OPC UA" plugin metrics in a bucket

Hi folks,
I’m trying to put all the metrics captured by this plugin (OPC UA) in its own dedicated bucket.
To do this I was thinking of using the “tagpass” filter.

These are the data to be filtered

_time:"2022-09-26 16:00:50";_field:"Quality";_measurement:"OPCUA";id:"ns=6;s=::AsGlobalPV:bBlink50ms";_value(string):"OK (0x0)"
_time:"2022-09-26 16:00:50";_field:"bBlink50ms";_measurement:"OPCUA";id:"ns=6;s=::AsGlobalPV:bBlink50ms";_value(boolean):true
_time:"2022-09-26 16:00:50";_field:"Quality";_measurement:"OPCUA";id:"ns=6;s=::AsGlobalPV:nGlobal";_value(string):"OK (0x0)"
_time:"2022-09-26 16:00:50";_field:"bBlink50ms";_measurement:"OPCUA";id:"ns=6;s=::AsGlobalPV:nGlobal";_value(number):191

This is the configuration of telegraf

###############################################################################
#                            OUTPUT PLUGINS                                   #
###############################################################################

# Configuration for sending metrics to InfluxDB 2.0
[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]
  token = "TOKEN"
  organization = "ORG"
  ## Destination bucket to write into.
  bucket = "OPCUA"
  [outputs.influxdb_v2.tagpass]
    _measurement = ["OPCUA"]


###############################################################################
#                            INPUT PLUGINS                                    #
###############################################################################

# Retrieve data from OPCUA devices
[[inputs.opcua]]
   alias = "OPCUA"
  ## Metric name
   name = "OPCUA"

   endpoint = "opc.tcp://192.168.1.200:4840"

   connect_timeout = "10s"

   request_timeout = "5s"

   security_policy = "None"
 
   security_mode = "None"
 
   timestamp = "gather"
  #
  ## Node ID configuration
  ## name              - field name to use in the output
  ## namespace         - OPC UA namespace of the node (integer value 0 thru 3)
  ## identifier_type   - OPC UA ID type (s=string, i=numeric, g=guid, b=opaque)
  ## identifier        - OPC UA ID (tag as shown in opcua browser)
  ## tags              - extra tags to be added to the output metric (optional)
  ## Example:
  ## {name="ProductUri", namespace="0", identifier_type="i", identifier="2262", tags=[["tag1","value1"],["tag2","value2]]}
   nodes = [
    {name="bBlink50ms", namespace="6", identifier_type="s", identifier="::AsGlobalPV:bBlink50ms"},
    {name="nGlobal", namespace="6", identifier_type="s", identifier="::AsGlobalPV:nGlobal"},
  ]

To filter I tried this:

[outputs.influxdb_v2.tagpass]
    _measurement= ["OPCUA"]

But no metrics are inserted inside the bucket.
am I doing something wrong? does anyone have an idea to put all the metrics in a bucket?

Tagpass is a mapping of tag keys, not their values. Read through the metric filtering options.

I think what you want to do is really select only the “OPCUA” measurement, then use namepass to filter on a measurement name.

1 Like

Thank @jpowers,
So I just use the “namepass = [” OPCUA “]” filter to filter the previous metrics.
I still don’t understand how the “tagpass” filter works.
Can I ask you for an example or is there any other documentation about it?

The short version is:

namepass → measurement name
tagpass → tag key + value must match

For example, assume you have the following measuremnet:

opcua,id="ns=6;s=::AsGlobalPV:bBlink50ms" quality="OK (0X))"

opcua is the measurement name and you can filter out that metric using the namepass or namedrop config option. It will look at the value of the measurment name itself.

id is the only tag in this example. With tagpass or tagdrop we can filter metrics that have the id tag with a specific value. So:

[outputs.influxdb_v2.tagpass]
    id = "ns=6;s=::AsGlobalPV:bBlink50ms"

Would pass the above example, but if the value of id is any different it will not.

1 Like

Ok, I inserted the plugin “[[outputs.file]]”
now it is clearer

this is the data to filter

OPCUA,host=PC-1,id=ns\=6;s\=::AsGlobalPV:bBlink50ms bBlink50ms=false,Quality="OK (0x0)" 1664288460000000000

with namepass everything works correctly by filtering in this way

namepass = ["OPCUA"]

when I use tagpass I still do something wrong
this is the filter I am using :confused:

  [outputs.influxdb_v2.tagpass]
    tag = ["host"]

when I use tagpass I still do something wrong

Can you state what you are seeing in InfluxDB and what you expect to see in InfluxDB?
Also how many outputs do you have?

1 Like

I want to put all the OPC UA plugin metrics in a bucket, in this case using tagpass.
Now Metrics are not written to its dedicated bucket with this filter.

  [outputs.influxdb_v2.tagpass]
    tag = ["host"]

these are my outputs

# Only OPC UA metrics should go here
[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]
  token = "token"
  organization = "xxx"
  ## Destination bucket to write into.
  bucket = "OPCUA"
  [outputs.influxdb_v2.tagpass]
    tag = ["host"]

# All the metrics go here
[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]
  token = "token"
  organization = "xxx"
  ## Destination bucket to write into.
  bucket = "ALL"

[[outputs.file]]
   files = ["./tmp/metrics.out"]
   data_format = "influx"
   rotation_interval = "24h"
   rotation_max_archives = 10

I think the easiest way to pass all metrics from a certain input, like OPCUA, is to use the namepass option instead.

namepass = ["OPCUA"]

This way if another measurement happens to have a “host” tag, does not also get added.

I have to admit I’ve made a mistake on my tagpass definition above (I’ve updated my above comment as well):

  [outputs.influxdb_v2.tagpass]
    tag = ["host"]

This will look for a tag key called “tag” with the value “host”:

# this will get added
OPCUA,tag=host,id=ns\=6;s\=::AsGlobalPV:bBlink50ms bBlink50ms=false,Quality="OK (0x0)" 1664288460000000000
# this will not
OPCUA,host=PC-1,id=ns\=6;s\=::AsGlobalPV:bBlink50ms bBlink50ms=false,Quality="OK (0x0)" 1664288460000000000

I think you were trying to do something like this:

  [outputs.influxdb_v2.tagpass]
    host = ["PC-1"]

But again this will push any metric with a tag that is host="PC-1"

My apologies for the confusion!

Thank you very much I finally managed to use the tagpass filter :smiley:
You should add the square brackets in the post you edited otherwise, it returns a TOML sintax error because it expects an array of admissible values

The only point I have yet to open is this:
This filter still don’t understand why it doesn’t work

# Configuration for sending metrics to InfluxDB 2.0
[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]
  token = "token"
  organization = "xxx"
  ## Destination bucket to write into.
  bucket = "OPCUA"
  [outputs.influxdb_v2.tagpass]
    Quality = ["OK (0x0)"]

Data that does not pass the filter

OPCUA,host=PC-1,id=ns\=6;s\=::AsGlobalPV:aGlobalArray Quality="OK (0x0)" 1664355950000000000
OPCUA,host=PC-1,id=ns\=6;s\=::AsGlobalPV:bBlink50ms bBlink50ms=false,Quality="OK (0x0)" 1664355950000000000
OPCUA,host=PC-1,id=ns\=6;s\=::AsGlobalPV:nGlobal nGlobal=198i,Quality="OK (0x0)" 1664355950000000000
OPCUA,host=PC-1,id=ns\=6;s\=::Program:V10.RPMx100 V10.RPMx100=0i,Quality="OK (0x0)" 1664355950000000000
OPCUA,host=PC-1,id=ns\=6;s\=::Program:V10.temp V10.temp=0i,Quality="OK (0x0)" 1664355950000000000
OPCUA,host=PC-1,id=ns\=6;s\=::Program:V10.powerOn V10.powerOn=false,Quality="OK (0x0)" 1664355950000000000
OPCUA,host=PC-1,id=ns\=6;s\=::Program:V10.torque V10.torque=0i,Quality="OK (0x0)" 1664355950000000000

Isn’t “Quality” a tag? If not how can I find out what all the tags are?

1 Like

Hi @Giu-seppe,
So we are outputting your data within line protocol which follows this structure:

<measurement>[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] [<timestamp>]
OPCUA,host=PC-1,id=ns\=6;s\=::AsGlobalPV:aGlobalArray Quality="OK (0x0)" 1664355950000000000

There for yours relates to:
Measurement = OPCUA
Tags = host,id
field = quality

2 Likes

Ok, so the structure is this:

  • initially, there is the measurement

  • after the comma there is the list of tags (also separated by commas)

  • after a space there is the list of fields (also separated by a comma)

  • after another space is the timestamp

right?

Hi @Giu-seppe,

Yep correct!

1 Like