github.com/netdata/go.d.plugin@v0.58.1/modules/pika/init.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package pika 4 5 import ( 6 "errors" 7 8 "github.com/netdata/go.d.plugin/agent/module" 9 "github.com/netdata/go.d.plugin/pkg/tlscfg" 10 11 "github.com/go-redis/redis/v8" 12 ) 13 14 func (p Pika) validateConfig() error { 15 if p.Address == "" { 16 return errors.New("'address' not set") 17 } 18 return nil 19 } 20 21 func (p Pika) initRedisClient() (*redis.Client, error) { 22 opts, err := redis.ParseURL(p.Address) 23 if err != nil { 24 return nil, err 25 } 26 27 tlsConfig, err := tlscfg.NewTLSConfig(p.TLSConfig) 28 if err != nil { 29 return nil, err 30 } 31 32 if opts.TLSConfig != nil && tlsConfig != nil { 33 tlsConfig.ServerName = opts.TLSConfig.ServerName 34 } 35 36 opts.PoolSize = 1 37 opts.TLSConfig = tlsConfig 38 opts.DialTimeout = p.Timeout.Duration 39 opts.ReadTimeout = p.Timeout.Duration 40 opts.WriteTimeout = p.Timeout.Duration 41 42 return redis.NewClient(opts), nil 43 } 44 45 func (p Pika) initCharts() (*module.Charts, error) { 46 return pikaCharts.Copy(), nil 47 }