summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2024-07-14 22:02:34 +0300
committerGitHub <noreply@github.com>2024-07-14 22:02:34 +0300
commit7cb342c77ead000339e7d9284d61f65bc41ecc48 (patch)
tree7888eb84711c5870c37ae1a9c5277a0b9c4c68f3 /src
parentfa4d1509d8f0efe7d85ec5f5f4e05e5e66fe208a (diff)
go.d smartctl: do scan only once on startup if interval is 0 (#18144)
Diffstat (limited to 'src')
-rw-r--r--src/go/plugin/go.d/modules/smartctl/collect.go2
-rw-r--r--src/go/plugin/go.d/modules/smartctl/config_schema.json2
-rw-r--r--src/go/plugin/go.d/modules/smartctl/metadata.yaml2
-rw-r--r--src/go/plugin/go.d/modules/smartctl/scan.go14
-rw-r--r--src/go/plugin/go.d/modules/smartctl/smartctl.go1
5 files changed, 13 insertions, 8 deletions
diff --git a/src/go/plugin/go.d/modules/smartctl/collect.go b/src/go/plugin/go.d/modules/smartctl/collect.go
index e8f8357d68..35585db62f 100644
--- a/src/go/plugin/go.d/modules/smartctl/collect.go
+++ b/src/go/plugin/go.d/modules/smartctl/collect.go
@@ -164,7 +164,7 @@ func (s *Smartctl) collectSmartDevice(mx map[string]int64, dev *smartDevice) {
}
func (s *Smartctl) isTimeToScan(now time.Time) bool {
- return now.After(s.lastScanTime.Add(s.ScanEvery.Duration()))
+ return s.ScanEvery.Duration().Seconds() != 0 && now.After(s.lastScanTime.Add(s.ScanEvery.Duration()))
}
func (s *Smartctl) isTimeToPollDevices(now time.Time) bool {
diff --git a/src/go/plugin/go.d/modules/smartctl/config_schema.json b/src/go/plugin/go.d/modules/smartctl/config_schema.json
index e03f8081da..afe7ce1a9f 100644
--- a/src/go/plugin/go.d/modules/smartctl/config_schema.json
+++ b/src/go/plugin/go.d/modules/smartctl/config_schema.json
@@ -20,7 +20,7 @@
},
"scan_every": {
"title": "Scan interval",
- "description": "Interval for discovering new devices using `smartctl --scan`, measured in seconds.",
+ "description": "Interval for discovering new devices using `smartctl --scan`, measured in seconds. Set to 0 to scan devices only once on startup.",
"type": "number",
"minimum": 1,
"default": 900
diff --git a/src/go/plugin/go.d/modules/smartctl/metadata.yaml b/src/go/plugin/go.d/modules/smartctl/metadata.yaml
index 0b54f69fbe..9293c25419 100644
--- a/src/go/plugin/go.d/modules/smartctl/metadata.yaml
+++ b/src/go/plugin/go.d/modules/smartctl/metadata.yaml
@@ -97,7 +97,7 @@ modules:
default_value: 5
required: false
- name: scan_every
- description: interval for discovering new devices using `smartctl --scan`, measured in seconds.
+ description: interval for discovering new devices using `smartctl --scan`, measured in seconds. Set to 0 to scan devices only once on startup.
default_value: 900
required: false
- name: poll_devices_every
diff --git a/src/go/plugin/go.d/modules/smartctl/scan.go b/src/go/plugin/go.d/modules/smartctl/scan.go
index e4291be4f9..06c8cdcb7f 100644
--- a/src/go/plugin/go.d/modules/smartctl/scan.go
+++ b/src/go/plugin/go.d/modules/smartctl/scan.go
@@ -53,11 +53,15 @@ func (s *Smartctl) scanDevices() (map[string]*scanDevice, error) {
// Accurate device type information is crucial because we use the `--device` option to gather data.
// Using the wrong type can lead to issues.
// For example, using 'scsi' for 'sat' devices prevents `smartctl` from issuing the necessary ATA commands.
- resp, _ := s.exec.deviceInfo(dev.name, dev.typ, s.NoCheckPowerMode)
- if resp != nil && isExitStatusHasBit(resp, 2) {
- correctType := "sat"
- s.Debugf("changing device '%s' type '%s' -> '%s'", dev.name, dev.typ, correctType)
- dev.typ = correctType
+ d := scanDevice{name: dev.name, typ: "sat"}
+ if _, ok := s.scannedDevices[d.key()]; ok {
+ dev.typ = "sat"
+ } else {
+ resp, _ := s.exec.deviceInfo(dev.name, dev.typ, s.NoCheckPowerMode)
+ if resp != nil && isExitStatusHasBit(resp, 2) {
+ s.Debugf("changing device '%s' type 'scsi' -> 'sat'", dev.name)
+ dev.typ = "sat"
+ }
}
}
diff --git a/src/go/plugin/go.d/modules/smartctl/smartctl.go b/src/go/plugin/go.d/modules/smartctl/smartctl.go
index 1ea1a8fbaf..0ba0491794 100644
--- a/src/go/plugin/go.d/modules/smartctl/smartctl.go
+++ b/src/go/plugin/go.d/modules/smartctl/smartctl.go
@@ -38,6 +38,7 @@ func New() *Smartctl {
DeviceSelector: "*",
},
charts: &module.Charts{},
+ forceScan: true,
deviceSr: matcher.TRUE(),
seenDevices: make(map[string]bool),
}