OpcUa Listener: Names must be unique?!?

Hi!

I want to monitor a production line using the OPC UA Listener.

The production line is controlled by one PLC, and has several stations. Each station provides some basic status information like if its running, cycle time, whatever.

So, I wrote this telegraf config:

[[inputs.opcua_listener]]
endpoint = "opc.tcp://ThePLC:4840"


[[inputs.opcua_listener.group]]
  name = "OpcTelegraf"
  namespace = "3"
  identifier_type = "s"
  default_tags = { Plc = "ThePLC" }
  nodes = [
    {identifier="Station1.Status", name="Status"},
    {identifier="Station2.Status", name="Status"},
    {identifier="Station3.Status", name="Status"}
  ]

and expect an output to influx like

opcua,id=ns\=3;s\=Station1 Status="Running",Quality="OK (0x0)" 1597....
opcua,id=ns\=3;s\=Station2 Status="Error",Quality="OK (0x0)" 1597.... 
opcua,id=ns\=3;s\=Station3 Status="Waiting",Quality="OK (0x0)" 1597....

However, telegraf throws an error:

Error running agent: could not initialize input inputs.opcua_listener: name “Status” is duplicated (metric name “OpcTelegraf”, tags “Plc=ThePLC”)

This is unexpected, and I don’t understand the reasoning behind. From an Influx point of view, same data from different sources should be stored in the same field name, while the source is written to a tag (and the source already IS written to tags). This would allow simple queries like SELECT “Status”… GROUP BY “id“.

Am I missing something? How can I use the same name?

What if you add another tag for the station number?

The format telegraf uses is the following:

  • Metric name (“name” of the group in this config)
    • Field1
    • Field2

The fieldnames in this plugin are the names defined inside the nodes, these have to be unique.

So if you want the station name to be the metric name you have to create 3 separate groups with a single field. And I think these groups can have the same name so your outputs is as you expect it.

Then again, I understand the confusion, because you would expect since the “id” is included as as tags, telegraf would interpret is as a different series. But apparently the opcua_listener config does not accept this.

Hope this helps.

Edited config
[[inputs.opcua_listener]]
  endpoint = "opc.tcp://ThePLC:4840"
  [inputs.opcua_listener.tags]
    Plc = "ThePLC"

[[inputs.opcua_listener.group]]
  name = "opcua"
  namespace = "3"
  identifier_type = "s"
  nodes = [
    {identifier="Station1.Status", name="Status"},
  ]
[[inputs.opcua_listener.group]]
  name = "opcua"
  namespace = "3"
  identifier_type = "s"
  nodes = [
    {identifier="Station2.Status", name="Status"},
  ]
[[inputs.opcua_listener.group]]
  name = "opcua"
  namespace = "3"
  identifier_type = "s"
  nodes = [
    {identifier="Station3.Status", name="Status"}
  ]

Hi!

Sorry for my long absence. I finally made it running, and it requires both of your suggestions.

@JeroenVH , multiple groups still lead to the same error message.

@R290 , I didn’t see first how to add individual tags, but I can add them to each group as below, my Telegraf starts up and records the data.

[[inputs.opcua_listener]]
  endpoint = "opc.tcp://ThePLC:4840"
  [inputs.opcua_listener.tags]
    Plc = "ThePLC"

[[inputs.opcua_listener.group]]
  name = "opcua"
  namespace = "3"
  identifier_type = "s"
  default_tags = { Station = "1" }
  nodes = [
    {identifier="Station1.Status", name="Status"}
  ]
[[inputs.opcua_listener.group]]
  name = "opcua"
  namespace = "3"
  identifier_type = "s"
  default_tags = { Station = "2" }
  nodes = [
    {identifier="Station2.Status", name="Status"}
  ]
[[inputs.opcua_listener.group]]
  name = "opcua"
  namespace = "3"
  identifier_type = "s"
  default_tags = { Station = "3" }
  nodes = [
    {identifier="Station3.Status", name="Status"}
  ]

I also checked if I can use more than one node per group (with different name, of course), and it works as well.

Finally, this gives a nice structure, IF you already know what’s which station (for the default tag), but makes it more complicated to create such a file automatically, and you don’t know the structure of the OPC namespace, yet.