github.com/netdata/go.d.plugin@v0.58.1/modules/vcsa/vcsa.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package vcsa 4 5 import ( 6 _ "embed" 7 "time" 8 9 "github.com/netdata/go.d.plugin/pkg/web" 10 11 "github.com/netdata/go.d.plugin/agent/module" 12 ) 13 14 //go:embed "config_schema.json" 15 var configSchema string 16 17 func init() { 18 module.Register("vcsa", module.Creator{ 19 JobConfigSchema: configSchema, 20 Defaults: module.Defaults{ 21 UpdateEvery: 5, // VCSA health checks freq is 5 second. 22 }, 23 Create: func() module.Module { return New() }, 24 }) 25 } 26 27 func New() *VCSA { 28 return &VCSA{ 29 Config: Config{ 30 HTTP: web.HTTP{ 31 Client: web.Client{ 32 Timeout: web.Duration{Duration: time.Second * 5}, 33 }, 34 }, 35 }, 36 charts: vcsaHealthCharts.Copy(), 37 } 38 } 39 40 type Config struct { 41 web.HTTP `yaml:",inline"` 42 } 43 44 type ( 45 VCSA struct { 46 module.Base 47 Config `yaml:",inline"` 48 49 client healthClient 50 51 charts *module.Charts 52 } 53 54 healthClient interface { 55 Login() error 56 Logout() error 57 Ping() error 58 ApplMgmt() (string, error) 59 DatabaseStorage() (string, error) 60 Load() (string, error) 61 Mem() (string, error) 62 SoftwarePackages() (string, error) 63 Storage() (string, error) 64 Swap() (string, error) 65 System() (string, error) 66 } 67 ) 68 69 func (vc *VCSA) Init() bool { 70 if err := vc.validateConfig(); err != nil { 71 vc.Error(err) 72 return false 73 } 74 75 c, err := vc.initHealthClient() 76 if err != nil { 77 vc.Errorf("error on creating health client : %vc", err) 78 return false 79 } 80 vc.client = c 81 82 vc.Debugf("using URL %s", vc.URL) 83 vc.Debugf("using timeout: %s", vc.Timeout.Duration) 84 85 return true 86 } 87 88 func (vc *VCSA) Check() bool { 89 err := vc.client.Login() 90 if err != nil { 91 vc.Error(err) 92 return false 93 } 94 95 return len(vc.Collect()) > 0 96 } 97 98 func (vc *VCSA) Charts() *module.Charts { 99 return vc.charts 100 } 101 102 func (vc *VCSA) Collect() map[string]int64 { 103 mx, err := vc.collect() 104 if err != nil { 105 vc.Error(err) 106 } 107 108 if len(mx) == 0 { 109 return nil 110 } 111 return mx 112 } 113 114 func (vc *VCSA) Cleanup() { 115 if vc.client == nil { 116 return 117 } 118 err := vc.client.Logout() 119 if err != nil { 120 vc.Errorf("error on logout : %v", err) 121 } 122 }