@cryptotaxi247 / netdata-1 / commits / 7cb342c77

go.d smartctl: do scan only once on startup if interval is 0 (#18144)

Ilya Mashchenko committed Jul 14, 2024 at 22:02 UTC 7cb342c77ead000339e7d9284d61f65bc41ecc48
5 files changed +13 -8
src/go/plugin/go.d/modules/smartctl/collect.go
+1 -1
@@ -164,7 +164,7 @@ func (s *Smartctl) collectSmartDevice(mx map[string]int64, dev *smartDevice) {
164 }
165
166 func (s *Smartctl) isTimeToScan(now time.Time) bool {
167 - return now.After(s.lastScanTime.Add(s.ScanEvery.Duration()))
167 + return s.ScanEvery.Duration().Seconds() != 0 && now.After(s.lastScanTime.Add(s.ScanEvery.Duration()))
168 }
169
170 func (s *Smartctl) isTimeToPollDevices(now time.Time) bool {
src/go/plugin/go.d/modules/smartctl/config_schema.json
+1 -1
@@ -20,7 +20,7 @@
20 },
21 "scan_every": {
22 "title": "Scan interval",
23 - "description": "Interval for discovering new devices using `smartctl --scan`, measured in seconds.",
23 + "description": "Interval for discovering new devices using `smartctl --scan`, measured in seconds. Set to 0 to scan devices only once on startup.",
24 "type": "number",
25 "minimum": 1,
26 "default": 900
src/go/plugin/go.d/modules/smartctl/metadata.yaml
+1 -1
@@ -97,7 +97,7 @@ modules:
97 default_value: 5
98 required: false
99 - name: scan_every
100 - description: interval for discovering new devices using `smartctl --scan`, measured in seconds.
100 + description: interval for discovering new devices using `smartctl --scan`, measured in seconds. Set to 0 to scan devices only once on startup.
101 default_value: 900
102 required: false
103 - name: poll_devices_every
src/go/plugin/go.d/modules/smartctl/scan.go
+9 -5
@@ -53,11 +53,15 @@ func (s *Smartctl) scanDevices() (map[string]*scanDevice, error) {
53 // Accurate device type information is crucial because we use the `--device` option to gather data.
54 // Using the wrong type can lead to issues.
55 // For example, using 'scsi' for 'sat' devices prevents `smartctl` from issuing the necessary ATA commands.
56 - resp, _ := s.exec.deviceInfo(dev.name, dev.typ, s.NoCheckPowerMode)
57 - if resp != nil && isExitStatusHasBit(resp, 2) {
58 - correctType := "sat"
59 - s.Debugf("changing device '%s' type '%s' -> '%s'", dev.name, dev.typ, correctType)
60 - dev.typ = correctType
56 + d := scanDevice{name: dev.name, typ: "sat"}
57 + if _, ok := s.scannedDevices[d.key()]; ok {
58 + dev.typ = "sat"
59 + } else {
60 + resp, _ := s.exec.deviceInfo(dev.name, dev.typ, s.NoCheckPowerMode)
61 + if resp != nil && isExitStatusHasBit(resp, 2) {
62 + s.Debugf("changing device '%s' type 'scsi' -> 'sat'", dev.name)
63 + dev.typ = "sat"
64 + }
65 }
66 }
67
src/go/plugin/go.d/modules/smartctl/smartctl.go
+1
@@ -38,6 +38,7 @@ func New() *Smartctl {
38 DeviceSelector: "*",
39 },
40 charts: &module.Charts{},
41 + forceScan: true,
42 deviceSr: matcher.TRUE(),
43 seenDevices: make(map[string]bool),
44 }