telegraf在iiot领域的基本应用(Modbus,OPC)

 熟悉telegraf是因为influxdb缘故,当时telegraf主要是作为granfa监控的agent一环,很多文章有相关的介绍,但作为java开发对telegraf(go语言开发)也仅仅只是适用级别,这边文章也只讲到一些简单的应用。希望能帮助大家!

https://github.com/influxdata/telegraf

telegraf最新的几版更新中,着重的对其关于扩展组件的更新中(最新一次在更新K8S监控)

telegraf在iiot领域的基本应用(Modbus,OPC)_第1张图片

目前最新的插件文档Plugin directory | Telegraf 1.22 Documentation

其他类型的插件配置方式放一边,找到关于iot领域插件

telegraf在iiot领域的基本应用(Modbus,OPC)_第2张图片

 里面有西门子传感器插件(S7)和MQTT还有OPCUA,仔细翻看源码,还包含modbus,tls等相关,有感兴趣的自行研究,我这里只实际操作采集OPCUA作为样例:

一.自行安装opcua软件

推荐教程:KepServer的下载安装与使用说明_牛奶咖啡13的博客-CSDN博客

        这里我安装的是kepserver6.5,新建通道channel2,设备device1,点位TAG5

telegraf在iiot领域的基本应用(Modbus,OPC)_第3张图片

   

二.下载telegraf,修改相关配置

opcua相关配置样例 telegraf/plugins/inputs/opcua at master · influxdata/telegraf · GitHub

相关核心配置

# Retrieve data from OPCUA devices
[[inputs.opcua]]
  ## Metric name
  name = "opcua"
  #
  ## OPC UA Endpoint URL
  endpoint = "opc.tcp://127.0.0.1:49320"
  #
  ## Maximum time allowed to establish a connect to the endpoint.
  connect_timeout = "10s"
  #
  ## Maximum time allowed for a request over the established connection.
  request_timeout = "5s"
  #
  ## Security policy, one of "None", "Basic128Rsa15", "Basic256",
  ## "Basic256Sha256", or "auto"
  security_policy = "None"    #这里和opcua一致
  #
  ## Security mode, one of "None", "Sign", "SignAndEncrypt", or "auto"
  security_mode = "None"    #这里和opcua一致
  #
  
 
  #
  ## Authentication Method, one of "Certificate", "UserName", or "Anonymous".  To
  ## authenticate using a specific ID, select 'Certificate' or 'UserName'
  auth_method = "Anonymous"
  #
  ## Username. Required for auth_method = "UserName"
  # username = ""
  #
  #
  ## Option to select the metric timestamp to use. Valid options are:
  ##     "gather" -- uses the time of receiving the data in telegraf
  ##     "server" -- uses the timestamp provided by the server
  ##     "source" -- uses the timestamp provided by the source
  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); deprecated in 1.25.0; use default_tags
  ## default_tags      - extra tags to be added to the output metric (optional)
  ##
  ## Use either the inline notation or the bracketed notation, not both.
  #
  ## Inline notation (default_tags not supported yet)
  # nodes = [
  #   {name="", namespace="", identifier_type="", identifier="", tags=[["tag1", "value1"], ["tag2", "value2"]},
  #   {name="", namespace="", identifier_type="", identifier=""},
  # ]
  #
  nodes = [
      {name="TAG5", namespace="2", identifier_type="s", identifier="channel2.device1.TAG5"},
    ]
  ## Bracketed notation

  ## Node Group
  ## Sets defaults so they aren't required in every node.
  ## Default values can be set for:
  ## * Metric name
  ## * OPC UA namespace
  ## * Identifier
  ## * Default tags
  ##
  ## Multiple node groups are allowed
  #[[inputs.opcua.group]]
  ## Group Metric name. Overrides the top level name.  If unset, the
  ## top level name is used.
  # name =
  #
  ## Group default namespace. If a node in the group doesn't set its
  ## namespace, this is used.
  # namespace =
  #
  ## Group default identifier type. If a node in the group doesn't set its
  ## namespace, this is used.
  # identifier_type =
  #
  ## Default tags that are applied to every node in this group. Can be
  ## overwritten in a node by setting a different value for the tag name.
  ##   example: default_tags = { tag1 = "value1" }
  # default_tags = {}
  #
  ## Node ID Configuration.  Array of nodes with the same settings as above.
  ## Use either the inline notation or the bracketed notation, not both.
  #
  ## Inline notation (default_tags not supported yet)
  # nodes = [
  #  {name="node1", namespace="", identifier_type="", identifier=""},
  #  {name="node2", namespace="", identifier_type="", identifier=""},
  #]
  #
  ## Bracketed notation
  # [[inputs.opcua.group.nodes]]
  #   name = "node1"
  #   namespace = ""
  #   identifier_type = ""
  #   identifier = ""
  #   default_tags = { tag1 = "override1", tag2 = "value2" }
  #
  # [[inputs.opcua.group.nodes]]
  #   name = "node2"
  #   namespace = ""
  #   identifier_type = ""
  #   identifier = ""

  ## Enable workarounds required by some devices to work correctly
  # [inputs.opcua.workarounds]
    ## Set additional valid status codes, StatusOK (0x0) is always considered valid
    # additional_valid_status_codes = ["0xC0"]

  # [inputs.opcua.request_workarounds]
    ## Use unregistered reads instead of registered reads
    # use_unregistered_reads = false
###############################################################################
#                            OUTPUT PLUGINS                                   #
###############################################################################


# Configuration for sending metrics to InfluxDB 2.0
[[outputs.influxdb_v2]]
   ## The URLs of the InfluxDB cluster nodes.
   ##
   ## Multiple URLs can be specified for a single cluster, only ONE of the
   ## urls will be written to each interval.
   ##   ex: urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]
   urls = ["你的地址"]

   ## Token for authentication.
   ##token = "你的token"

   ## Organization is the name of the organization you wish to write to.
   organization = "你的组织"

   ## Destination bucket to write into.
   bucket = "opc_test"

   ## The value of this tag will be used to determine the bucket.  If this
   ## tag is not set the 'bucket' option is used as the default.
   # bucket_tag = ""

   ## If true, the bucket tag will not be added to the metric.
   # exclude_bucket_tag = false

   ## Timeout for HTTP messages.
   # timeout = "5s"

   ## Additional HTTP headers
   # http_headers = {"X-Special-Header" = "Special-Value"}

   ## HTTP Proxy override, if unset values the standard proxy environment
   ## variables are consulted to determine which proxy, if any, should be used.
   # http_proxy = "http://corporate.proxy:3128"

   ## HTTP User-Agent
   # user_agent = "telegraf"

   ## Content-Encoding for write request body, can be set to "gzip" to
   ## compress body or "identity" to apply no encoding.
   # content_encoding = "gzip"

   ## Enable or disable uint support for writing uints influxdb 2.0.
   # influx_uint_support = false

   ## Optional TLS Config for use on HTTP connections.
   # tls_ca = "/etc/telegraf/ca.pem"
   # tls_cert = "/etc/telegraf/cert.pem"
   # tls_key = "/etc/telegraf/key.pem"
   ## Use TLS but skip chain & host verification
   # insecure_skip_verify = false



我是采集到influxdb中,基本完成

telegraf在iiot领域的基本应用(Modbus,OPC)_第4张图片

三.可能出现的错误

1.opcua认证错误

这里认证方式要和配置里对应

telegraf在iiot领域的基本应用(Modbus,OPC)_第5张图片

2.node id找不到

这里配置找的issues里有几个样例解释的不太详细,容易误导,具体错误是identifier(唯一性id错误),这里可以理解为点位

 identifier="channel2.device1.TAG5"

你可能感兴趣的:(java,工业物联网,学习,java)