From 299f9f963edba39a6141d1f5ea66add06e835727 Mon Sep 17 00:00:00 2001 From: hys Date: Wed, 3 Dec 2025 19:17:13 +0800 Subject: [PATCH] fix: omit open error device --- collector/diskstats_linux.go | 2 +- collector/smartctl.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index 7d3678063f..a37dc4dad3 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -314,7 +314,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { smartJSON, exists := getDeviceResult(smartctlResult, stats.DeviceName) if !exists { - c.logger.Info("get device result from smartctl failed") + c.logger.Info("get device result from smartctl failed", "deviceName", stats.DeviceName) } info, err := getUdevDeviceProperties(stats.MajorNumber, stats.MinorNumber) diff --git a/collector/smartctl.go b/collector/smartctl.go index 156d41083b..62f3597bde 100644 --- a/collector/smartctl.go +++ b/collector/smartctl.go @@ -62,6 +62,9 @@ func (s *Smartctl) scan() ([]scanDevice, error) { } devices := make([]scanDevice, 0) for _, device := range scan.Devices { + if device.OpenError != "" { + continue + } dev := scanDevice{ Name: device.Name, Type: device.Type, @@ -273,9 +276,10 @@ type smartctlScanJSON struct { ExitStatus int `json:"exit_status"` } `json:"smartctl"` Devices []struct { - Name string `json:"name"` - InfoName string `json:"info_name"` - Type string `json:"type"` - Protocol string `json:"protocol"` + Name string `json:"name"` + InfoName string `json:"info_name"` + Type string `json:"type"` + Protocol string `json:"protocol"` + OpenError string `json:"open_error,omitempty"` } `json:"devices"` }