From 1c4fa5628c428123d2ceb3463df35ff115442346 Mon Sep 17 00:00:00 2001 From: "CHEVY S. HUNGERFORD" Date: Fri, 26 Jan 2018 20:40:34 -0600 Subject: [PATCH 1/2] giving temperature more verbose output --- host/host_linux.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index e0b4b60f..c309ed58 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -591,13 +591,30 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err } } - for _, match := range files { - match = strings.Split(match, "_")[0] - name, err := ioutil.ReadFile(filepath.Join(filepath.Dir(match), "name")) + // example directory + // device/ temp1_crit_alarm temp2_crit_alarm temp3_crit_alarm temp4_crit_alarm temp5_crit_alarm temp6_crit_alarm temp7_crit_alarm + // name temp1_input temp2_input temp3_input temp4_input temp5_input temp6_input temp7_input + // power/ temp1_label temp2_label temp3_label temp4_label temp5_label temp6_label temp7_label + // subsystem/ temp1_max temp2_max temp3_max temp4_max temp5_max temp6_max temp7_max + // temp1_crit temp2_crit temp3_crit temp4_crit temp5_crit temp6_crit temp7_crit uevent + for _, file := range files { + if filepath.Match(file, "/class/hwmon/hwmon*/temp*_label") { + continue + } + + filename := strings.Split(filepath.Base(file), "_") + c, _ := ioutil.ReadFile(filepath.Join(filepath.Dir(file), filename[0] + "_label")) + + var corename string + if c != nil { + corename = fmt.Sprintf("%s_", strings.TrimSpace(strings.ToLower(string(c)))) + } + + name, err := ioutil.ReadFile(filepath.Join(filepath.Dir(file), "name")) if err != nil { return temperatures, err } - current, err := ioutil.ReadFile(match + "_input") + current, err := ioutil.ReadFile(file) if err != nil { return temperatures, err } @@ -605,8 +622,10 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err if err != nil { continue } + + tempName = strings.TrimSpace(strings.ToLower(string(strings.Join(filename[1:], "")))) temperatures = append(temperatures, TemperatureStat{ - SensorKey: strings.TrimSpace(string(name)), + SensorKey: fmt.Sprintf("%s_%s", strings.TrimSpace(string(name)), corename, tempName), Temperature: temperature / 1000.0, }) } From 29f8dfa1ad243a863c94f394a9bfb922ea7e2da1 Mon Sep 17 00:00:00 2001 From: "CHEVY S. HUNGERFORD" Date: Sat, 27 Jan 2018 10:11:51 -0600 Subject: [PATCH 2/2] fixing SensorKey output --- host/host_linux.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index c309ed58..53242584 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -598,22 +598,27 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err // subsystem/ temp1_max temp2_max temp3_max temp4_max temp5_max temp6_max temp7_max // temp1_crit temp2_crit temp3_crit temp4_crit temp5_crit temp6_crit temp7_crit uevent for _, file := range files { - if filepath.Match(file, "/class/hwmon/hwmon*/temp*_label") { + filename := strings.Split(filepath.Base(file), "_") + if filename[1] == "label" { + // Do not try to read the temperature of the label file continue } - filename := strings.Split(filepath.Base(file), "_") - c, _ := ioutil.ReadFile(filepath.Join(filepath.Dir(file), filename[0] + "_label")) - - var corename string + // Get the label of the temperature you are reading + var label string + c, _ := ioutil.ReadFile(filepath.Join(filepath.Dir(file), filename[0]+"_label")) if c != nil { - corename = fmt.Sprintf("%s_", strings.TrimSpace(strings.ToLower(string(c)))) + //format the label from "Core 0" to "core0_" + label = fmt.Sprintf("%s_", strings.Join(strings.Split(strings.TrimSpace(strings.ToLower(string(c))), " "), "")) } + // Get the name of the tempearture you are reading name, err := ioutil.ReadFile(filepath.Join(filepath.Dir(file), "name")) if err != nil { return temperatures, err } + + // Get the temperature reading current, err := ioutil.ReadFile(file) if err != nil { return temperatures, err @@ -623,9 +628,9 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err continue } - tempName = strings.TrimSpace(strings.ToLower(string(strings.Join(filename[1:], "")))) + tempName := strings.TrimSpace(strings.ToLower(string(strings.Join(filename[1:], "")))) temperatures = append(temperatures, TemperatureStat{ - SensorKey: fmt.Sprintf("%s_%s", strings.TrimSpace(string(name)), corename, tempName), + SensorKey: fmt.Sprintf("%s_%s%s", strings.TrimSpace(string(name)), label, tempName), Temperature: temperature / 1000.0, }) }