From f6a9d104f8fd934b10e0cbff871979a8f1e1e897 Mon Sep 17 00:00:00 2001 From: Mya Longmire Date: Thu, 10 Jun 2021 14:51:33 -0600 Subject: [PATCH] Feature powermode smartctl (#9306) Co-authored-by: Steven Soroka --- plugins/inputs/smart/smart.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/plugins/inputs/smart/smart.go b/plugins/inputs/smart/smart.go index 4533ea768..b0f189d69 100644 --- a/plugins/inputs/smart/smart.go +++ b/plugins/inputs/smart/smart.go @@ -25,19 +25,23 @@ var ( // Device Model: APPLE SSD SM256E // Product: HUH721212AL5204 // Model Number: TS128GMTE850 - modelInfo = regexp.MustCompile("^(Device Model|Product|Model Number):\\s+(.*)$") + modelInfo = regexp.MustCompile(`^(Device Model|Product|Model Number):\s+(.*)$`) // Serial Number: S0X5NZBC422720 - serialInfo = regexp.MustCompile("(?i)^Serial Number:\\s+(.*)$") + serialInfo = regexp.MustCompile(`(?i)^Serial Number:\s+(.*)$`) // LU WWN Device Id: 5 002538 655584d30 - wwnInfo = regexp.MustCompile("^LU WWN Device Id:\\s+(.*)$") + wwnInfo = regexp.MustCompile(`^LU WWN Device Id:\s+(.*)$`) // User Capacity: 251,000,193,024 bytes [251 GB] - userCapacityInfo = regexp.MustCompile("^User Capacity:\\s+([0-9,]+)\\s+bytes.*$") + userCapacityInfo = regexp.MustCompile(`^User Capacity:\s+([0-9,]+)\s+bytes.*$`) // SMART support is: Enabled - smartEnabledInfo = regexp.MustCompile("^SMART support is:\\s+(\\w+)$") + smartEnabledInfo = regexp.MustCompile(`^SMART support is:\s+(\w+)$`) + // Power mode is: ACTIVE or IDLE or Power mode was: STANDBY + powermodeInfo = regexp.MustCompile(`^Power mode \w+:\s+(\w+)`) + // Device is in STANDBY mode + standbyInfo = regexp.MustCompile(`^Device is in\s+(\w+)`) // SMART overall-health self-assessment test result: PASSED // SMART Health Status: OK // PASSED, FAILED, UNKNOWN - smartOverallHealth = regexp.MustCompile("^(SMART overall-health self-assessment test result|SMART Health Status):\\s+(\\w+).*$") + smartOverallHealth = regexp.MustCompile(`^(SMART overall-health self-assessment test result|SMART Health Status):\s+(\w+).*$`) // sasNvmeAttr is a SAS or NVME SMART attribute sasNvmeAttr = regexp.MustCompile(`^([^:]+):\s+(.+)$`) @@ -46,7 +50,7 @@ var ( // 1 Raw_Read_Error_Rate -O-RC- 200 200 000 - 0 // 5 Reallocated_Sector_Ct PO--CK 100 100 000 - 0 // 192 Power-Off_Retract_Count -O--C- 097 097 000 - 14716 - attribute = regexp.MustCompile("^\\s*([0-9]+)\\s(\\S+)\\s+([-P][-O][-S][-R][-C][-K])\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9-]+)\\s+([-\\w]+)\\s+([\\w\\+\\.]+).*$") + attribute = regexp.MustCompile(`^\s*([0-9]+)\s(\S+)\s+([-P][-O][-S][-R][-C][-K])\s+([0-9]+)\s+([0-9]+)\s+([0-9-]+)\s+([-\w]+)\s+([\w\+\.]+).*$`) // Additional Smart Log for NVME device:nvme0 namespace-id:ffffffff // key normalized raw @@ -693,11 +697,24 @@ func gatherDisk(acc telegraf.Accumulator, timeout config.Duration, usesudo, coll deviceFields["health_ok"] = health[2] == "PASSED" || health[2] == "OK" } + // checks to see if there is a power mode to print to user + // if not look for Device is in STANDBY which happens when + // nocheck is set to standby (will exit to not spin up the disk) + // otherwise nothing is found so nothing is printed (NVMe does not show power) + if power := powermodeInfo.FindStringSubmatch(line); len(power) > 1 { + deviceTags["power"] = power[1] + } else { + if power := standbyInfo.FindStringSubmatch(line); len(power) > 1 { + deviceTags["power"] = power[1] + } + } + tags := map[string]string{} fields := make(map[string]interface{}) if collectAttributes { - keys := [...]string{"device", "model", "serial_no", "wwn", "capacity", "enabled"} + //add power mode + keys := [...]string{"device", "model", "serial_no", "wwn", "capacity", "enabled", "power"} for _, key := range keys { if value, ok := deviceTags[key]; ok { tags[key] = value