From 56a9454730f90f03d37fa691bae3cd1fcf3f656c Mon Sep 17 00:00:00 2001 From: Pablo Garcia Date: Thu, 7 Nov 2024 11:54:46 +0100 Subject: [PATCH 1/4] Add a wait between disks checks --- collector/pkg/collector/metrics.go | 4 ++-- collector/pkg/config/config.go | 1 + example.collector.yaml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/collector/pkg/collector/metrics.go b/collector/pkg/collector/metrics.go index 5d453dd..5ae3364 100644 --- a/collector/pkg/collector/metrics.go +++ b/collector/pkg/collector/metrics.go @@ -15,6 +15,7 @@ import ( "os" "os/exec" "strings" + "time" ) type MetricsCollector struct { @@ -90,8 +91,7 @@ func (mc *MetricsCollector) Run() error { //go mc.Collect(&wg, device.WWN, device.DeviceName, device.DeviceType) mc.Collect(device.WWN, device.DeviceName, device.DeviceType) - // TODO: we may need to sleep for between each call to smartctl -a - //time.Sleep(30 * time.Millisecond) + time.Sleep(time.Duration(mc.config.GetInt("commands.metrics_smartctl_wait")) * time.Millisecond) } //mc.logger.Infoln("Main: Waiting for workers to finish") diff --git a/collector/pkg/config/config.go b/collector/pkg/config/config.go index 45bb3b8..3e81880 100644 --- a/collector/pkg/config/config.go +++ b/collector/pkg/config/config.go @@ -47,6 +47,7 @@ func (c *configuration) Init() error { c.SetDefault("commands.metrics_scan_args", "--scan --json") c.SetDefault("commands.metrics_info_args", "--info --json") c.SetDefault("commands.metrics_smart_args", "--xall --json") + c.SetDefault("commands.metrics_smartctl_wait", 0) //c.SetDefault("collect.short.command", "-a -o on -S on") diff --git a/example.collector.yaml b/example.collector.yaml index d1fc9f1..0469610 100644 --- a/example.collector.yaml +++ b/example.collector.yaml @@ -81,6 +81,7 @@ devices: # metrics_scan_args: '--scan --json' # used to detect devices # metrics_info_args: '--info --json' # used to determine device unique ID & register device with Scrutiny # metrics_smart_args: '--xall --json' # used to retrieve smart data for each device. +# metrics_smartctl_wait: 0 # time to wait in seconds between each disk's check ######################################################################################################################## From c168e1e9fcb63fbb299cf9aa499927e96c0389ba Mon Sep 17 00:00:00 2001 From: Pablo Garcia Alvarez Date: Mon, 11 Nov 2024 22:07:57 +0100 Subject: [PATCH 2/4] Add check for the wait --- collector/pkg/collector/metrics.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/collector/pkg/collector/metrics.go b/collector/pkg/collector/metrics.go index 5ae3364..7ff4fc8 100644 --- a/collector/pkg/collector/metrics.go +++ b/collector/pkg/collector/metrics.go @@ -91,7 +91,9 @@ func (mc *MetricsCollector) Run() error { //go mc.Collect(&wg, device.WWN, device.DeviceName, device.DeviceType) mc.Collect(device.WWN, device.DeviceName, device.DeviceType) - time.Sleep(time.Duration(mc.config.GetInt("commands.metrics_smartctl_wait")) * time.Millisecond) + if mc.config.GetInt("commands.metrics_smartctl_wait") > 0 { + time.Sleep(time.Duration(mc.config.GetInt("commands.metrics_smartctl_wait")) * time.Millisecond) + } } //mc.logger.Infoln("Main: Waiting for workers to finish") From 85d98316f3111cd15c7a0835081fe242c0539eb0 Mon Sep 17 00:00:00 2001 From: Pablo Garcia Date: Tue, 26 Nov 2024 10:46:27 +0100 Subject: [PATCH 3/4] Issue 706: Fix time unit --- collector/pkg/collector/metrics.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/collector/pkg/collector/metrics.go b/collector/pkg/collector/metrics.go index 7ff4fc8..3f2088a 100644 --- a/collector/pkg/collector/metrics.go +++ b/collector/pkg/collector/metrics.go @@ -4,6 +4,12 @@ import ( "bytes" "encoding/json" "fmt" + "net/url" + "os" + "os/exec" + "strings" + "time" + "github.com/analogj/scrutiny/collector/pkg/common/shell" "github.com/analogj/scrutiny/collector/pkg/config" "github.com/analogj/scrutiny/collector/pkg/detect" @@ -11,11 +17,6 @@ import ( "github.com/analogj/scrutiny/collector/pkg/models" "github.com/samber/lo" "github.com/sirupsen/logrus" - "net/url" - "os" - "os/exec" - "strings" - "time" ) type MetricsCollector struct { @@ -92,7 +93,7 @@ func (mc *MetricsCollector) Run() error { mc.Collect(device.WWN, device.DeviceName, device.DeviceType) if mc.config.GetInt("commands.metrics_smartctl_wait") > 0 { - time.Sleep(time.Duration(mc.config.GetInt("commands.metrics_smartctl_wait")) * time.Millisecond) + time.Sleep(time.Duration(mc.config.GetInt("commands.metrics_smartctl_wait")) * 1000 * time.Millisecond) } } @@ -115,7 +116,7 @@ func (mc *MetricsCollector) Validate() error { return nil } -//func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string, deviceType string) { +// func (mc *MetricsCollector) Collect(wg *sync.WaitGroup, deviceWWN string, deviceName string, deviceType string) { func (mc *MetricsCollector) Collect(deviceWWN string, deviceName string, deviceType string) { //defer wg.Done() if len(deviceWWN) == 0 { From 9ad96e6d37a89d69a6e4802ab0d12fbde981aa3f Mon Sep 17 00:00:00 2001 From: Pablo Garcia Date: Tue, 26 Nov 2024 15:13:44 +0100 Subject: [PATCH 4/4] Change to time.Seconds --- collector/pkg/collector/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/pkg/collector/metrics.go b/collector/pkg/collector/metrics.go index 3f2088a..10bb98d 100644 --- a/collector/pkg/collector/metrics.go +++ b/collector/pkg/collector/metrics.go @@ -93,7 +93,7 @@ func (mc *MetricsCollector) Run() error { mc.Collect(device.WWN, device.DeviceName, device.DeviceType) if mc.config.GetInt("commands.metrics_smartctl_wait") > 0 { - time.Sleep(time.Duration(mc.config.GetInt("commands.metrics_smartctl_wait")) * 1000 * time.Millisecond) + time.Sleep(time.Duration(mc.config.GetInt("commands.metrics_smartctl_wait")) * time.Second) } }