diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/go/collectors/go.d.plugin/modules/vcsa/vcsa.go | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/vcsa/vcsa.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/vcsa/vcsa.go | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/vcsa/vcsa.go b/src/go/collectors/go.d.plugin/modules/vcsa/vcsa.go new file mode 100644 index 000000000..f5e86d082 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/vcsa/vcsa.go @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package vcsa + +import ( + _ "embed" + "errors" + "time" + + "github.com/netdata/netdata/go/go.d.plugin/agent/module" + "github.com/netdata/netdata/go/go.d.plugin/pkg/web" +) + +//go:embed "config_schema.json" +var configSchema string + +func init() { + module.Register("vcsa", module.Creator{ + JobConfigSchema: configSchema, + Defaults: module.Defaults{ + UpdateEvery: 5, // VCSA health checks freq is 5 second. + }, + Create: func() module.Module { return New() }, + }) +} + +func New() *VCSA { + return &VCSA{ + Config: Config{ + HTTP: web.HTTP{ + Client: web.Client{ + Timeout: web.Duration(time.Second * 5), + }, + }, + }, + charts: vcsaHealthCharts.Copy(), + } +} + +type Config struct { + web.HTTP `yaml:",inline" json:""` + UpdateEvery int `yaml:"update_every" json:"update_every"` +} + +type ( + VCSA struct { + module.Base + Config `yaml:",inline" json:""` + + charts *module.Charts + + client healthClient + } + + healthClient interface { + Login() error + Logout() error + Ping() error + ApplMgmt() (string, error) + DatabaseStorage() (string, error) + Load() (string, error) + Mem() (string, error) + SoftwarePackages() (string, error) + Storage() (string, error) + Swap() (string, error) + System() (string, error) + } +) + +func (vc *VCSA) Configuration() any { + return vc.Config +} + +func (vc *VCSA) Init() error { + if err := vc.validateConfig(); err != nil { + vc.Error(err) + return err + } + + c, err := vc.initHealthClient() + if err != nil { + vc.Errorf("error on creating health client : %vc", err) + return err + } + vc.client = c + + vc.Debugf("using URL %s", vc.URL) + vc.Debugf("using timeout: %s", vc.Timeout) + + return nil +} + +func (vc *VCSA) Check() error { + err := vc.client.Login() + if err != nil { + vc.Error(err) + return err + } + + mx, err := vc.collect() + if err != nil { + vc.Error(err) + return err + } + + if len(mx) == 0 { + return errors.New("no metrics collected") + } + + return nil +} + +func (vc *VCSA) Charts() *module.Charts { + return vc.charts +} + +func (vc *VCSA) Collect() map[string]int64 { + mx, err := vc.collect() + if err != nil { + vc.Error(err) + } + + if len(mx) == 0 { + return nil + } + return mx +} + +func (vc *VCSA) Cleanup() { + if vc.client == nil { + return + } + err := vc.client.Logout() + if err != nil { + vc.Errorf("error on logout : %v", err) + } +} |