forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go.d rewrite python.d/adaptec_raid (netdata#17428)
- Loading branch information
Showing
21 changed files
with
1,448 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## All available configuration options, their descriptions and default values: | ||
## https://github.com/netdata/netdata/tree/master/src/go/collectors/go.d.plugin/modules/adaptecraid#readme | ||
|
||
jobs: | ||
- name: adaptec_raid |
107 changes: 107 additions & 0 deletions
107
src/go/collectors/go.d.plugin/modules/adaptecraid/adaptec.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package adaptecraid | ||
|
||
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("adaptec_raid", module.Creator{ | ||
JobConfigSchema: configSchema, | ||
Defaults: module.Defaults{ | ||
UpdateEvery: 10, | ||
}, | ||
Create: func() module.Module { return New() }, | ||
}) | ||
} | ||
|
||
func New() *AdaptecRaid { | ||
return &AdaptecRaid{ | ||
Config: Config{ | ||
Timeout: web.Duration(time.Second * 2), | ||
}, | ||
charts: &module.Charts{}, | ||
lds: make(map[string]bool), | ||
pds: make(map[string]bool), | ||
} | ||
} | ||
|
||
type Config struct { | ||
UpdateEvery int `yaml:"update_every" json:"update_every"` | ||
Timeout web.Duration `yaml:"timeout" json:"timeout"` | ||
} | ||
|
||
type ( | ||
AdaptecRaid struct { | ||
module.Base | ||
Config `yaml:",inline" json:""` | ||
|
||
charts *module.Charts | ||
|
||
exec arcconfCli | ||
|
||
lds map[string]bool | ||
pds map[string]bool | ||
} | ||
arcconfCli interface { | ||
logicalDevicesInfo() ([]byte, error) | ||
physicalDevicesInfo() ([]byte, error) | ||
} | ||
) | ||
|
||
func (a *AdaptecRaid) Configuration() any { | ||
return a.Config | ||
} | ||
|
||
func (a *AdaptecRaid) Init() error { | ||
arcconfExec, err := a.initArcconfCliExec() | ||
if err != nil { | ||
a.Errorf("arcconf exec initialization: %v", err) | ||
return err | ||
} | ||
a.exec = arcconfExec | ||
|
||
return nil | ||
} | ||
|
||
func (a *AdaptecRaid) Check() error { | ||
mx, err := a.collect() | ||
if err != nil { | ||
a.Error(err) | ||
return err | ||
} | ||
|
||
if len(mx) == 0 { | ||
return errors.New("no metrics collected") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *AdaptecRaid) Charts() *module.Charts { | ||
return a.charts | ||
} | ||
|
||
func (a *AdaptecRaid) Collect() map[string]int64 { | ||
mx, err := a.collect() | ||
if err != nil { | ||
a.Error(err) | ||
} | ||
|
||
if len(mx) == 0 { | ||
return nil | ||
} | ||
|
||
return mx | ||
} | ||
|
||
func (a *AdaptecRaid) Cleanup() {} |
Oops, something went wrong.