tariqbuilds / linux-dash

A beautiful web dashboard for Linux
https://afaqurk.github.io/linux-dash/
MIT License
10.43k stars 1.2k forks source link

Average CPU temperature by cores data #465

Closed alozovskoy closed 2 years ago

alozovskoy commented 6 years ago

https://github.com/afaqurk/linux-dash/issues/451 - Getting an average value of CPU cores temperature when sensors not return "Physical" metric.

Unfortunately, i can't check it on real hardware (all my devices return data with "Physical" metric), but it work on "synthetic" tests.

Jiab77 commented 5 years ago

I was looking to apply this pull request but it needs lm-sensors to be installed otherwise it won't work.

Surrealcrow commented 4 years ago

Had to make a change in my dashboard to work (ubuntu 18),

first change, $(type -P sensors 2) .old code was including the /usr/bin/sensor in the json second -f 7 instead of 3 to get the temp value

hope you find it useful

cpu_temp() { local ID= [ -f /etc/os-release ] && source /etc/os-release case "$ID" in "raspbian") cpu=$(</sys/class/thermal/thermal_zone0/temp) echo "$((cpu/1000))" | _parseAndPrint ;; ) if "$(type -P sensors 2)" >/dev/null ; then returnString=sensors

amd

    if [[ "${returnString/"k10"}" != "${returnString}" ]] ; then
      $ECHO ${returnString##*k10} | $CUT -d ' ' -f 6 | $CUT -c 2- | $CUT -c 1-4
    #intel
    elif [[ "${returnString/"core"}" != "${returnString}" ]] ; then
      fromcore=${returnString##*"coretemp"}
      $ECHO ${fromcore##*Physical}  | $CUT -d ' ' **-f 7** | $CUT -c 2-5 | _parseAndPrint
    fi
  else
    $ECHO "[]" | _parseAndPrint
  fi
;;

esac }

Jiab77 commented 4 years ago

@Surrealcrow or simply add |"ubuntu" after "raspbian" in the switch/case block.

It has the first advantage to not need to have lm-sensors to be installed 😉

Surrealcrow commented 4 years ago

@Jiab77 i was thinking about that, however after a test i noticed that the reported temp in the raspian option was off by some degrees, I don't really know if it is only my case.

thanks!

HardRock88 commented 3 years ago

Hi, I have same problem on my intel based PC under linux mint 20.04

sensors output was:

coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +32.0°C  (high = +100.0°C, crit = +100.0°C)
Core 0:        +30.0°C  (high = +100.0°C, crit = +100.0°C)
Core 1:        +30.0°C  (high = +100.0°C, crit = +100.0°C)
Core 2:        +31.0°C  (high = +100.0°C, crit = +100.0°C)
Core 3:        +32.0°C  (high = +100.0°C, crit = +100.0°C)

acpitz-acpi-0
Adapter: ACPI interface
temp1:        +27.8°C  (crit = +105.0°C)

iwlwifi_1-virtual-0
Adapter: Virtual device
temp1:        +37.0°C  

nvme-pci-0100
Adapter: PCI adapter
Composite:    +33.9°C  (low  =  -0.1°C, high = +74.8°C)
                       (crit = +79.8°C)

so I fixed it like this on my code local copy:

--- a/app/server/linux_json_api.sh
+++ b/app/server/linux_json_api.sh
@@ -92,7 +92,7 @@ cpu_temp() {
       echo "$((cpu/1000))" | _parseAndPrint
     ;;
     *)
-      if type -P sensors 2>/dev/null; then
+      if "$(type -P sensors 2)">/dev/null; then
         returnString=`sensors`
         #amd
         if [[ "${returnString/"k10"}" != "${returnString}" ]] ; then
@@ -100,7 +100,7 @@ cpu_temp() {
         #intel
         elif [[ "${returnString/"core"}" != "${returnString}" ]] ; then
           fromcore=${returnString##*"coretemp"}
-          $ECHO ${fromcore##*Physical}  | $CUT -d ' ' -f 3 | $CUT -c 2-5 | _parseAndPrint
+          $ECHO ${fromcore##*Package} | $CUT -d ' ' -f 3 | $CUT -c 2-5 | _parseAndPrint
         fi
       else
         $ECHO "[]" | _parseAndPrint