mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-28 13:48:49 +08:00
Merge pull request #485 from cshunger/linux-temperature
Linux temperature
This commit is contained in:
commit
c432be29cc
@ -591,13 +591,35 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, match := range files {
|
// example directory
|
||||||
match = strings.Split(match, "_")[0]
|
// device/ temp1_crit_alarm temp2_crit_alarm temp3_crit_alarm temp4_crit_alarm temp5_crit_alarm temp6_crit_alarm temp7_crit_alarm
|
||||||
name, err := ioutil.ReadFile(filepath.Join(filepath.Dir(match), "name"))
|
// 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 {
|
||||||
|
filename := strings.Split(filepath.Base(file), "_")
|
||||||
|
if filename[1] == "label" {
|
||||||
|
// Do not try to read the temperature of the label file
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
//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 {
|
if err != nil {
|
||||||
return temperatures, err
|
return temperatures, err
|
||||||
}
|
}
|
||||||
current, err := ioutil.ReadFile(match + "_input")
|
|
||||||
|
// Get the temperature reading
|
||||||
|
current, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return temperatures, err
|
return temperatures, err
|
||||||
}
|
}
|
||||||
@ -605,8 +627,10 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tempName := strings.TrimSpace(strings.ToLower(string(strings.Join(filename[1:], ""))))
|
||||||
temperatures = append(temperatures, TemperatureStat{
|
temperatures = append(temperatures, TemperatureStat{
|
||||||
SensorKey: strings.TrimSpace(string(name)),
|
SensorKey: fmt.Sprintf("%s_%s%s", strings.TrimSpace(string(name)), label, tempName),
|
||||||
Temperature: temperature / 1000.0,
|
Temperature: temperature / 1000.0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user