chore(inputs.opcua): Add option to collect client debug logging (#14595)
This commit is contained in:
parent
8cd487d052
commit
f7208e5339
|
|
@ -3,11 +3,13 @@ package opcua
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log" //nolint:depguard // just for debug
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gopcua/opcua"
|
||||
"github.com/gopcua/opcua/debug"
|
||||
"github.com/gopcua/opcua/ua"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
|
|
@ -44,6 +46,7 @@ type OpcUAClientConfig struct {
|
|||
AuthMethod string `toml:"auth_method"`
|
||||
ConnectTimeout config.Duration `toml:"connect_timeout"`
|
||||
RequestTimeout config.Duration `toml:"request_timeout"`
|
||||
ClientTrace bool `toml:"client_trace"`
|
||||
|
||||
OptionalFields []string `toml:"optional_fields"`
|
||||
Workarounds OpcUAWorkarounds `toml:"workarounds"`
|
||||
|
|
@ -87,15 +90,20 @@ func (o *OpcUAClientConfig) validateEndpoint() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *OpcUAClientConfig) CreateClient(log telegraf.Logger) (*OpcUAClient, error) {
|
||||
func (o *OpcUAClientConfig) CreateClient(telegrafLogger telegraf.Logger) (*OpcUAClient, error) {
|
||||
err := o.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if o.ClientTrace {
|
||||
debug.Enable = true
|
||||
debug.Logger = log.New(&DebugLogger{Log: telegrafLogger}, "", 0)
|
||||
}
|
||||
|
||||
c := &OpcUAClient{
|
||||
Config: o,
|
||||
Log: log,
|
||||
Log: telegrafLogger,
|
||||
}
|
||||
c.Log.Debug("Initialising OpcUAClient")
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package opcua
|
||||
|
||||
import (
|
||||
"github.com/influxdata/telegraf"
|
||||
)
|
||||
|
||||
// DebugLogger logs messages from opcua at the debug level.
|
||||
type DebugLogger struct {
|
||||
Log telegraf.Logger
|
||||
}
|
||||
|
||||
func (l *DebugLogger) Write(p []byte) (n int, err error) {
|
||||
l.Log.Debug(string(p))
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
@ -71,6 +71,12 @@ to use them.
|
|||
## "source" -- uses the timestamp provided by the source
|
||||
# timestamp = "gather"
|
||||
#
|
||||
## Client trace messages
|
||||
## When set to true, and debug mode enabled in the agent settings, the OPCUA
|
||||
## client's messages are included in telegraf logs. These messages are very
|
||||
## noisey, but essential for debugging issues.
|
||||
# client_trace = false
|
||||
#
|
||||
## Include additional Fields in each metric
|
||||
## Available options are:
|
||||
## DataType -- OPC-UA Data Type (string)
|
||||
|
|
|
|||
|
|
@ -43,6 +43,12 @@
|
|||
## "source" -- uses the timestamp provided by the source
|
||||
# timestamp = "gather"
|
||||
#
|
||||
## Client trace messages
|
||||
## When set to true, and debug mode enabled in the agent settings, the OPCUA
|
||||
## client's messages are included in telegraf logs. These messages are very
|
||||
## noisey, but essential for debugging issues.
|
||||
# client_trace = false
|
||||
#
|
||||
## Include additional Fields in each metric
|
||||
## Available options are:
|
||||
## DataType -- OPC-UA Data Type (string)
|
||||
|
|
|
|||
|
|
@ -97,6 +97,13 @@ to use them.
|
|||
# e.g.: json_timestamp_format = "2006-01-02T15:04:05Z07:00"
|
||||
#timestamp_format = ""
|
||||
#
|
||||
#
|
||||
## Client trace messages
|
||||
## When set to true, and debug mode enabled in the agent settings, the OPCUA
|
||||
## client's messages are included in telegraf logs. These messages are very
|
||||
## noisey, but essential for debugging issues.
|
||||
# client_trace = false
|
||||
#
|
||||
## Include additional Fields in each metric
|
||||
## Available options are:
|
||||
## DataType -- OPC-UA Data Type (string)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,13 @@
|
|||
# e.g.: json_timestamp_format = "2006-01-02T15:04:05Z07:00"
|
||||
#timestamp_format = ""
|
||||
#
|
||||
#
|
||||
## Client trace messages
|
||||
## When set to true, and debug mode enabled in the agent settings, the OPCUA
|
||||
## client's messages are included in telegraf logs. These messages are very
|
||||
## noisey, but essential for debugging issues.
|
||||
# client_trace = false
|
||||
#
|
||||
## Include additional Fields in each metric
|
||||
## Available options are:
|
||||
## DataType -- OPC-UA Data Type (string)
|
||||
|
|
|
|||
Loading…
Reference in New Issue