From 34585d88dfe3eed9006437ee05a52dd6c41cf918 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Wed, 30 Jun 2021 14:14:04 +0200 Subject: [PATCH 1/4] Skip InfiniBand collector if perfquery does not exist --- collectors/infinibandMetric.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/collectors/infinibandMetric.go b/collectors/infinibandMetric.go index 4878fff..de3561d 100644 --- a/collectors/infinibandMetric.go +++ b/collectors/infinibandMetric.go @@ -11,6 +11,7 @@ import ( ) const LIDFILE = `/sys/class/infiniband/mlx4_0/ports/1/lid` +const PERFQUERY = `/usr/sbin/perfquery` type InfinibandCollector struct { MetricCollector @@ -20,6 +21,13 @@ func (m *InfinibandCollector) Init() error { m.name = "InfinibandCollector" m.setup() _, err := ioutil.ReadFile(string(LIDFILE)) + if err != nil { + return err + } + _, err = ioutil.ReadFile(string(PERFQUERY)) + if err != nil { + return err + } return err } @@ -33,7 +41,7 @@ func (m *InfinibandCollector) Read(interval time.Duration) { args := fmt.Sprintf("-r %s 1 0xf000", string(buffer)) - command := exec.Command("/usr/sbin/perfquery", args) + command := exec.Command(PERFQUERY, args) command.Wait() stdout, err := command.Output() if err != nil { From 586c6c12acc7cc6d42083ba069b3ae8119d7f7dc Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Wed, 30 Jun 2021 16:56:47 +0200 Subject: [PATCH 2/4] Add SSL to InfluxDB sink --- sinks/influxSink.go | 12 ++++++++++-- sinks/metricSink.go | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sinks/influxSink.go b/sinks/influxSink.go index c5d23d4..90292c4 100644 --- a/sinks/influxSink.go +++ b/sinks/influxSink.go @@ -2,6 +2,7 @@ package sinks import ( "context" + "crypto/tls" "errors" "fmt" influxdb2 "github.com/influxdata/influxdb-client-go/v2" @@ -19,14 +20,20 @@ type InfluxSink struct { func (s *InfluxSink) connect() error { var auth string - uri := fmt.Sprintf("http://%s:%s", s.host, s.port) + var uri string + if s.ssl { + uri = fmt.Sprintf("https://%s:%s", s.host, s.port) + } else { + uri = fmt.Sprintf("http://%s:%s", s.host, s.port) + } if len(s.user) == 0 { auth = s.password } else { auth = fmt.Sprintf("%s:%s", s.user, s.password) } log.Print("Using URI ", uri, " Org ", s.organization, " Bucket ", s.database) - s.client = influxdb2.NewClient(uri, auth) + s.client = influxdb2.NewClientWithOptions(uri, auth, + influxdb2.DefaultOptions().SetTLSConfig(&tls.Config{InsecureSkipVerify: true})) s.writeApi = s.client.WriteAPIBlocking(s.organization, s.database) return nil } @@ -45,6 +52,7 @@ func (s *InfluxSink) Init(config SinkConfig) error { s.organization = config.Organization s.user = config.User s.password = config.Password + s.ssl = config.SSL return s.connect() } diff --git a/sinks/metricSink.go b/sinks/metricSink.go index 5c84d8c..c357cdd 100644 --- a/sinks/metricSink.go +++ b/sinks/metricSink.go @@ -12,6 +12,7 @@ type SinkConfig struct { Password string `json:"password"` Organization string `json:"organization"` Type string `json:"type"` + SSL bool `json:"ssl"` } type Sink struct { @@ -21,6 +22,7 @@ type Sink struct { password string database string organization string + ssl bool } type SinkFuncs interface { From e4564979566436d4ed082080b82b962d237957a0 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Wed, 30 Jun 2021 17:03:56 +0200 Subject: [PATCH 3/4] Update sink README with SSL for Influx sink --- sinks/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sinks/README.md b/sinks/README.md index 059ed88..03856ba 100644 --- a/sinks/README.md +++ b/sinks/README.md @@ -5,7 +5,7 @@ The base class/configuration is located in `metricSink.go`. # Sinks * `stdoutSink.go`: Writes all metrics to `stdout` in InfluxDB line protocol. The sink does not use https://github.com/influxdata/line-protocol to reduce the executed code for debugging -* `influxSink.go`: Writes all metrics to an InfluxDB database instance using a blocking writer. It uses https://github.com/influxdata/influxdb-client-go . Configuration for the server, port, user, password, database name and organisation are in the global configuration file. It uses the v2 API of Influx. +* `influxSink.go`: Writes all metrics to an InfluxDB database instance using a blocking writer. It uses https://github.com/influxdata/influxdb-client-go . Configuration for the server, port, ssl, password, database name and organisation are in the global configuration file. The 'password' is used for the token and the 'database' for the bucket. It uses the v2 API of Influx. * `natsSink.go`: Sends all metrics to an NATS server using the InfluxDB line protocol as encoding. It uses https://github.com/nats-io/nats.go . Configuration for the server, port, user, password and database name are in the global configuration file. The database name is used as subject for the NATS messages. # Installation From 1cc9491eca53b3823101c9da3f3a0da5618ecd40 Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Fri, 20 Aug 2021 12:17:46 +0200 Subject: [PATCH 4/4] Reset encoder buffer in nats sink --- sinks/natsSink.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sinks/natsSink.go b/sinks/natsSink.go index 6a938b8..77a0431 100644 --- a/sinks/natsSink.go +++ b/sinks/natsSink.go @@ -66,7 +66,7 @@ func (s *NatsSink) Write(measurement string, tags map[string]string, fields map[ return err } s.client.Publish(s.database, s.buffer.Bytes()) - + s.buffer.Reset() } return nil }