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

CPU Temperature not working #393

Closed bmuessig closed 7 years ago

bmuessig commented 8 years ago

The CPU temperatures are not displayed.

My sensors output is:

coretemp-isa-0000 Adapter: ISA adapter Core 0: +36.0°C (crit = +90.0°C)

The CPU is a single core i686 Intel Atom, I am using PHP on Ubuntu Server 16.04 LTS.

I got it working by changing the lower cut -d ' ' -f 3 in cpu_temp.sh to cut -d ' ' -f 7.

tariqbuilds commented 8 years ago

hmm. That is interesting output. I am also on Ubuntu 16.04 LTS with an Intel processor (i5) but my output is parsing fine with the current implementation.

Looks like we will have to find the differentiating factor for your system and add a condition here: https://github.com/afaqurk/linux-dash/blob/master/server/modules/shell_files/cpu_temp.sh#L8

I will need more info to help identify those differentiating factors. Could you please post the output of:

sensors -v

Please note that any changes to fix this issue would be bundles with v2.0 release.

r-nikhil commented 8 years ago

I have the same issue on my raspberry pi also. The CPU temperatures are not displayed

tariqbuilds commented 8 years ago

@rnikhil275 @bmuessig : What do you get when you run sensors -v?

bmuessig commented 8 years ago

This is the version information of my sensors: sensors version 3.4.0 with libsensors version 3.4.0

In case you want it, here's my cpuinfo:

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 28
model name      : Intel(R) Atom(TM) CPU N280   @ 1.66GHz
stepping        : 2
microcode       : 0x20a
cpu MHz         : 1000.000
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fdiv_bug        : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 xtpr pdcm movbe lahf_lm dtherm
bugs            :
bogomips        : 3324.76
clflush size    : 64
cache_alignment : 64
address sizes   : 32 bits physical, 32 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 28
model name      : Intel(R) Atom(TM) CPU N280   @ 1.66GHz
stepping        : 2
microcode       : 0x20a
cpu MHz         : 1000.000
cache size      : 512 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 1
initial apicid  : 1
fdiv_bug        : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 xtpr pdcm movbe lahf_lm dtherm
bugs            :
bogomips        : 3324.76
clflush size    : 64
cache_alignment : 64
address sizes   : 32 bits physical, 32 bits virtual
power management:
r-nikhil commented 8 years ago

This is the version information of my sensors in my raspberry pi: sensors version 3.3.5 with libsensors version 3.3.5

electrofink commented 8 years ago

For a slightly easier and stable way to parse the output from lm_sensors, I once wrote a bash script that transforms the detailed output of "sensors" into JSON. It might be of use for this project.

#!/bin/bash

# Split sensors output on empty lines and write it to temporary files
awk -v RS="" '{print $0 > "/tmp/lmsens-"$1}' <(sensors -Au)

# Construct a json array consisting of the individual sensors with their readings
JSON="["

for file in /tmp/lmsens-*; do

    # Generate JSON from lm_sensors output through awk
    SENSOR=$(awk -F: 'BEGIN { print "{" }

    FNR == 1 { getline nextline < FILENAME }
    {
        getline nextline < FILENAME
        if ($2 == "") {
            print "\""$1"\": {"
        } else {
            split(nextline, nextfields)
            gsub(/^[ \t]+|[ \t]+$/, "", $1)
            gsub(/^[ \t]+|[ \t]+$/, "", $2)
            if (nextfields[2] != "") {
                print "\""$1"\":\""$2"\","
            } else {
                print "\""$1"\":\""$2"\" },"
            }
        }
    }
    END { print "}}" }' "$file")

    # Replace last comma with closing curly brace
    JSON="$JSON ${SENSOR%,*} } ${SENSOR##*,},"

    # Clean up temporary file
    rm "$file"
done

# Remove last comma and add closing square bracket for end of array
JSON="${JSON%,*} ${JSON##*,}]"

# Just print the damn thing
echo "$JSON"

Example detailed sensors output snippet:

coretemp-isa-0000
Core 0:
  temp2_input: 54.000
  temp2_max: 105.000
  temp2_crit: 105.000
  temp2_crit_alarm: 0.000
Core 1:
  temp3_input: 54.000
  temp3_max: 105.000
  temp3_crit: 105.000
  temp3_crit_alarm: 0.000
Core 2:
  temp4_input: 57.000
  temp4_max: 105.000
  temp4_crit: 105.000
  temp4_crit_alarm: 0.000
Core 3:
  temp5_input: 57.000
  temp5_max: 105.000
  temp5_crit: 105.000
  temp5_crit_alarm: 0.000

Transformed by the above script:

  {
    "coretemp-isa-0000": {
      "Core 0": {
        "temp2_input": "56.000",
        "temp2_max": "105.000",
        "temp2_crit": "105.000",
        "temp2_crit_alarm": "0.000"
      },
      "Core 1": {
        "temp3_input": "56.000",
        "temp3_max": "105.000",
        "temp3_crit": "105.000",
        "temp3_crit_alarm": "0.000"
      },
      "Core 2": {
        "temp4_input": "58.000",
        "temp4_max": "105.000",
        "temp4_crit": "105.000",
        "temp4_crit_alarm": "0.000"
      },
      "Core 3": {
        "temp5_input": "58.000",
        "temp5_max": "105.000",
        "temp5_crit": "105.000",
        "temp5_crit_alarm": "0.000"
      }
    }
  }

The bash script handles multiple sensor sources and puts them into an array, this just serves as an example for one of them (namely the CPU temperature)

vanbwodonk commented 7 years ago

TO: Raspberry Pi Users

I'm on Raspberry Pi 3. I did dirty hack and change cpu_temp.sh into this

awk '{printf "%3.1f\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp

And it works,

DarthKegRaider commented 7 years ago

Thanks bmuessig,

I have an IBM server with an old X5570 Xeon on Ubuntu Server 16.04 (Ubuntu 16.04.1 LTS 4.4.0-47-generic). The default script would not work, however your change to "7" worked. Thanks heaps.

lscpu

Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 26 Model name: Intel(R) Xeon(R) CPU X5570 @ 2.93GHz Stepping: 5 CPU MHz: 1596.000 CPU max MHz: 2926.0000 CPU min MHz: 1596.0000 BogoMIPS: 5866.80 Virtualisation: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 8192K NUMA node0 CPU(s): 0-7 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm tpr_shadow vnmi flexpriority ept vpid dtherm