diff --git a/agent/internal/httpapi/extras.go b/agent/internal/httpapi/extras.go index ee5c1da..ede5e42 100644 --- a/agent/internal/httpapi/extras.go +++ b/agent/internal/httpapi/extras.go @@ -120,6 +120,11 @@ func (s *Server) handleMetrics(w http.ResponseWriter, r *http.Request) { } else { resp["npu"] = map[string]any{"error": err.Error()} } + if temp, err := metrics.ReadTemperature(); err == nil { + resp["temperature"] = temp + } else { + resp["temperature"] = map[string]any{"error": err.Error()} + } media := map[string]any{"supported": s.proc != nil && s.proc.Enabled()} if s.proc == nil || !s.proc.Enabled() { diff --git a/agent/internal/metrics/metrics.go b/agent/internal/metrics/metrics.go index 877cbc3..6e99da0 100644 --- a/agent/internal/metrics/metrics.go +++ b/agent/internal/metrics/metrics.go @@ -263,7 +263,8 @@ func ParseLoadAvg(data string) (LoadAvg, error) { } type NPULoad struct { - UsagePct float64 `json:"usage_pct"` + UsagePct float64 `json:"usage_pct"` + Cores map[string]float64 `json:"cores,omitempty"` } func ReadNPULoad() (*NPULoad, error) { @@ -273,31 +274,67 @@ func ReadNPULoad() (*NPULoad, error) { } defer f.Close() scanner := bufio.NewScanner(f) - var total, idle float64 + cores := map[string]float64{} + n := 0 for scanner.Scan() { line := scanner.Text() - parts := strings.Split(line, "%") - for _, p := range parts { - p = strings.TrimSpace(p) - if idx := strings.LastIndex(p, " "); idx >= 0 { - p = p[idx+1:] + // Find each "CoreN: XX%" pattern + idx := 0 + for { + coreStart := strings.Index(line[idx:], "Core") + if coreStart < 0 { + break } - if strings.HasSuffix(p, "%") { - continue + coreStart += idx + colon := strings.Index(line[coreStart:], ":") + if colon < 0 { + break } - v, err := strconv.ParseFloat(strings.TrimSpace(p), 64) + colon += coreStart + coreName := strings.TrimSpace(line[coreStart:colon]) + // Find value after colon up to % or comma or end + valEnd := strings.Index(line[colon+1:], "%") + if valEnd < 0 { + break + } + valEnd += colon + 1 + valStr := strings.TrimSpace(line[colon+1 : valEnd]) + v, err := strconv.ParseFloat(valStr, 64) if err == nil { - total += 100 - idle += v + cores[coreName] = v + n++ } + idx = valEnd + 1 } } - if total == 0 { + if n == 0 { return nil, ErrNotSupported } - usage := 100 - (idle / total * 100) - if usage < 0 { - usage = 0 + var total float64 + for _, v := range cores { + total += v } - return &NPULoad{UsagePct: usage}, nil + avg := total / float64(n) + return &NPULoad{UsagePct: avg, Cores: cores}, nil +} + +type Temperature struct { + Zone string `json:"zone"` + Celsius float64 `json:"celsius"` +} + +func ReadTemperature() (*Temperature, error) { + raw, err := os.ReadFile("/sys/class/thermal/thermal_zone0/temp") + if err != nil { + return nil, err + } + zone, _ := os.ReadFile("/sys/class/thermal/thermal_zone0/type") + milli, err := strconv.ParseFloat(strings.TrimSpace(string(raw)), 64) + if err != nil { + return nil, err + } + return &Temperature{ + Zone: strings.TrimSpace(string(zone)), + Celsius: milli / 1000, + }, nil } diff --git a/agent/rk3588-agent_linux_arm64 b/agent/rk3588-agent_linux_arm64 index 39c9255..ea9d86d 100755 Binary files a/agent/rk3588-agent_linux_arm64 and b/agent/rk3588-agent_linux_arm64 differ diff --git a/third_party/rknpu2/examples/rknn_yolov5_android_apk_demo/gradle/wrapper/gradle-wrapper.properties b/third_party/rknpu2/examples/rknn_yolov5_android_apk_demo/gradle/wrapper/gradle-wrapper.properties index 2e6e589..69b7a16 100644 --- a/third_party/rknpu2/examples/rknn_yolov5_android_apk_demo/gradle/wrapper/gradle-wrapper.properties +++ b/third_party/rknpu2/examples/rknn_yolov5_android_apk_demo/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon May 11 15:07:02 CST 2026 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists