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

CPU temp support for other platforms (fix #661) #677

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed


## [0.3.8-alpha.1] 2022-11-16

### Added
Expand All @@ -27,6 +28,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- [System] Improve the feedback function, you can submit feedback in the bottom right corner of WebUI.

### Fixed
- [System] Fix CPU Temp for other platforms ([#661](https://github.com/IceWhaleTech/CasaOS/issues/661))

## [0.3.7.1] 2022-11-04

### Fixed
Expand All @@ -48,7 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Apps] App list update mechanism improved, now you can see the latest apps in App Store immediately.
- [Storage] Fixed a lot of known issues


### Added
- [Storage] Disk merge (Beta), you can merge multiple disks into a single storage space (currently you need to enable this feature from the command line)

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func init() {
service.Cache = cache.Init()

service.GetToken()
service.GetCPUThermalZone()

service.NewVersionApp = make(map[string]string)
route.InitFunction()
Expand Down
43 changes: 39 additions & 4 deletions service/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/disk"
"github.com/shirou/gopsutil/v3/host"
Expand Down Expand Up @@ -300,12 +301,46 @@ func (s *systemService) IsServiceRunning(name string) bool {
return strings.TrimSpace(status) == "running"
}

// find thermal_zone of cpu.
// assertions:
// * thermal_zone "type" and "temp" are required fields
// (https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-thermal)
func GetCPUThermalZone() string {
keyName := "cpu_thermal_zone"

var path string
if result, ok := Cache.Get(keyName); ok {
path, ok = result.(string)
if ok {
return path
}
}

for i := 0; i < 100; i++ {
path := "/sys/devices/virtual/thermal/thermal_zone" + strconv.Itoa(i)
if _, err := os.Stat(path); !os.IsNotExist(err) {
name := strings.TrimSuffix(string(file.ReadFullFile(path + "/type")), "\n")
cpu_types := []string{"x86_pkg_temp", "cpu", "CPU", "soc"}
for _, s := range cpu_types {
if strings.HasPrefix(name, s) {
loger.Info(fmt.Sprintf("CPU thermal zone found: %s, path: %s.", name, path))
Cache.SetDefault(keyName, path)
return path
}
}
} else {
loger.Error("CPUThermalZone not found. CPU Temp will not be displayed.")
break
}
}
return ""
}

func (s *systemService) GetCPUTemperature() int {
outPut := ""
if file.Exists("/sys/class/thermal/thermal_zone0/temp") {
outPut = string(file.ReadFullFile("/sys/class/thermal/thermal_zone0/temp"))
} else if file.Exists("/sys/class/hwmon/hwmon0/temp1_input") {
outPut = string(file.ReadFullFile("/sys/class/hwmon/hwmon0/temp1_input"))
path := GetCPUThermalZone()
if len(path)>0 {
outPut = string(file.ReadFullFile(path + "/temp"))
} else {
outPut = "0"
}
Expand Down