Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature powermode smartctl #9306

Merged
merged 7 commits into from
Jun 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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+(.+)$`)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down