Return error at Init for skip collectors early

This commit is contained in:
Thomas Roehl 2021-05-14 19:21:16 +02:00
parent 9b59429a93
commit 6b6e28d4c7
9 changed files with 19 additions and 9 deletions

View File

@ -13,9 +13,10 @@ type CpustatCollector struct {
MetricCollector MetricCollector
} }
func (m *CpustatCollector) Init() { func (m *CpustatCollector) Init() error {
m.name = "CpustatCollector" m.name = "CpustatCollector"
m.setup() m.setup()
return nil
} }
func ParseStatLine(line string, out map[string]interface{}) { func ParseStatLine(line string, out map[string]interface{}) {

View File

@ -16,9 +16,11 @@ type InfinibandCollector struct {
MetricCollector MetricCollector
} }
func (m *InfinibandCollector) Init() { func (m *InfinibandCollector) Init() error {
m.name = "InfinibandCollector" m.name = "InfinibandCollector"
m.setup() m.setup()
_, err := ioutil.ReadFile(string(LIDFILE))
return err
} }
func (m *InfinibandCollector) Read(interval time.Duration) { func (m *InfinibandCollector) Read(interval time.Duration) {

View File

@ -71,7 +71,7 @@ func getSocketCpus() map[C.int]int {
return outmap return outmap
} }
func (m *LikwidCollector) Init() { func (m *LikwidCollector) Init() error {
m.name = "LikwidCollector" m.name = "LikwidCollector"
m.setup() m.setup()
cpulist := CpuList() cpulist := CpuList()
@ -111,6 +111,7 @@ func (m *LikwidCollector) Init() {
} }
C.free(unsafe.Pointer(cstr)) C.free(unsafe.Pointer(cstr))
} }
return nil
} }
func (m *LikwidCollector) Read(interval time.Duration) { func (m *LikwidCollector) Read(interval time.Duration) {

View File

@ -13,9 +13,10 @@ type LoadavgCollector struct {
MetricCollector MetricCollector
} }
func (m *LoadavgCollector) Init() { func (m *LoadavgCollector) Init() error {
m.name = "LoadavgCollector" m.name = "LoadavgCollector"
m.setup() m.setup()
return nil
} }
func (m *LoadavgCollector) Read(interval time.Duration) { func (m *LoadavgCollector) Read(interval time.Duration) {

View File

@ -14,9 +14,11 @@ type LustreCollector struct {
MetricCollector MetricCollector
} }
func (m *LustreCollector) Init() { func (m *LustreCollector) Init() error {
m.name = "LustreCollector" m.name = "LustreCollector"
m.setup() m.setup()
_, err := ioutil.ReadFile(string(LUSTREFILE))
return err
} }
func (m *LustreCollector) Read(interval time.Duration) { func (m *LustreCollector) Read(interval time.Duration) {

View File

@ -15,9 +15,10 @@ type MemstatCollector struct {
MetricCollector MetricCollector
} }
func (m *MemstatCollector) Init() { func (m *MemstatCollector) Init() error {
m.name = "MemstatCollector" m.name = "MemstatCollector"
m.setup() m.setup()
return nil
} }
func (m *MemstatCollector) Read(interval time.Duration) { func (m *MemstatCollector) Read(interval time.Duration) {

View File

@ -10,7 +10,7 @@ import (
type MetricGetter interface { type MetricGetter interface {
Name() string Name() string
Init() Init() error
Read(time.Duration) Read(time.Duration)
Close() Close()
GetNodeMetric() map[string]interface{} GetNodeMetric() map[string]interface{}

View File

@ -15,9 +15,10 @@ type NetstatCollector struct {
MetricCollector MetricCollector
} }
func (m *NetstatCollector) Init() { func (m *NetstatCollector) Init() error {
m.name = "NetstatCollector" m.name = "NetstatCollector"
m.setup() m.setup()
return nil
} }
func (m *NetstatCollector) Read(interval time.Duration) { func (m *NetstatCollector) Read(interval time.Duration) {

View File

@ -14,9 +14,10 @@ type TopProcsCollector struct {
MetricCollector MetricCollector
} }
func (m *TopProcsCollector) Init() { func (m *TopProcsCollector) Init() error {
m.name = "TopProcsCollector" m.name = "TopProcsCollector"
m.setup() m.setup()
return nil
} }
func (m *TopProcsCollector) Read(interval time.Duration) { func (m *TopProcsCollector) Read(interval time.Duration) {