Skip to content

Commit

Permalink
go.d rewrite python.d/adaptec_raid (netdata#17428)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Apr 17, 2024
1 parent 40ba94b commit b8760c6
Show file tree
Hide file tree
Showing 21 changed files with 1,448 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/go/collectors/go.d.plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ see the appropriate collector readme.

| Name | Monitors |
|:------------------------------------------------------------------------------------------------------------------------------|:-----------------------------:|
| [adaptec_raid](https://github.com/netdata/netdata/tree/master/src/go/collectors/go.d.plugin/modules/adaptecraid) | Adaptec Hardware RAID |
| [activemq](https://github.com/netdata/netdata/tree/master/src/go/collectors/go.d.plugin/modules/activemq) | ActiveMQ |
| [apache](https://github.com/netdata/netdata/tree/master/src/go/collectors/go.d.plugin/modules/apache) | Apache |
| [bind](https://github.com/netdata/netdata/tree/master/src/go/collectors/go.d.plugin/modules/bind) | ISC Bind |
Expand Down
1 change: 1 addition & 0 deletions src/go/collectors/go.d.plugin/config/go.d.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ max_procs: 0
# If you want to change any value, you need to uncomment out it first.
# IMPORTANT: Do not remove all spaces, just remove # symbol. There should be a space before module name.
modules:
# adaptec_raid: yes
# activemq: yes
# apache: yes
# bind: yes
Expand Down
5 changes: 5 additions & 0 deletions src/go/collectors/go.d.plugin/config/go.d/adaptec_raid.conf
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 src/go/collectors/go.d.plugin/modules/adaptecraid/adaptec.go
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() {}
Loading

0 comments on commit b8760c6

Please sign in to comment.