summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/sensors/sensors.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/sensors/sensors.go')
-rw-r--r--src/go/collectors/go.d.plugin/modules/sensors/sensors.go111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/sensors/sensors.go b/src/go/collectors/go.d.plugin/modules/sensors/sensors.go
new file mode 100644
index 0000000000..f909811d7c
--- /dev/null
+++ b/src/go/collectors/go.d.plugin/modules/sensors/sensors.go
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package sensors
+
+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("sensors", module.Creator{
+ JobConfigSchema: configSchema,
+ Defaults: module.Defaults{
+ UpdateEvery: 10,
+ },
+ Create: func() module.Module { return New() },
+ })
+}
+
+func New() *Sensors {
+ return &Sensors{
+ Config: Config{
+ BinaryPath: "/usr/bin/sensors",
+ Timeout: web.Duration(time.Second * 2),
+ },
+ charts: &module.Charts{},
+ sensors: make(map[string]bool),
+ }
+}
+
+type Config struct {
+ UpdateEvery int `yaml:"update_every" json:"update_every"`
+ Timeout web.Duration `yaml:"timeout" json:"timeout"`
+ BinaryPath string `yaml:"binary_path" json:"binary_path"`
+}
+
+type (
+ Sensors struct {
+ module.Base
+ Config `yaml:",inline" json:""`
+
+ charts *module.Charts
+
+ exec sensorsCLI
+
+ sensors map[string]bool
+ }
+ sensorsCLI interface {
+ sensorsInfo() ([]byte, error)
+ }
+)
+
+func (s *Sensors) Configuration() any {
+ return s.Config
+}
+
+func (s *Sensors) Init() error {
+ if err := s.validateConfig(); err != nil {
+ s.Errorf("config validation: %s", err)
+ return err
+ }
+
+ sensorsExec, err := s.initSensorsCliExec()
+ if err != nil {
+ s.Errorf("sensors exec initialization: %v", err)
+ return err
+ }
+ s.exec = sensorsExec
+
+ return nil
+}
+
+func (s *Sensors) Check() error {
+ mx, err := s.collect()
+ if err != nil {
+ s.Error(err)
+ return err
+ }
+
+ if len(mx) == 0 {
+ return errors.New("no metrics collected")
+ }
+
+ return nil
+}
+
+func (s *Sensors) Charts() *module.Charts {
+ return s.charts
+}
+
+func (s *Sensors) Collect() map[string]int64 {
+ mx, err := s.collect()
+ if err != nil {
+ s.Error(err)
+ }
+
+ if len(mx) == 0 {
+ return nil
+ }
+
+ return mx
+}
+
+func (s *Sensors) Cleanup() {}