Skip to content

Commit

Permalink
fix(api): read temperature from main if no per-core data is found
Browse files Browse the repository at this point in the history
this is important for raspberry pi, because it has no lm-sensors

fix #107
  • Loading branch information
MauriceNino committed Jun 9, 2022
1 parent adb6607 commit 523e7a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 12 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ WORKDIR /app

RUN \
apk update &&\
apk add git make clang build-base lsblk dmidecode util-linux lm-sensors speedtest-cli &&\
apk add \
git \
make \
clang \
build-base \
lsblk \
dmidecode \
util-linux \
lm-sensors \
speedtest-cli &&\
apk add -f \
raspberrypi &&\
git config --global --add safe.directory /app

# DEV #
Expand Down
9 changes: 5 additions & 4 deletions apps/api/src/dynamic-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ export const cpuObs = createBufferedInterval(
const loads = (await si.currentLoad()).cpus;

let temps: si.Systeminformation.CpuTemperatureData['cores'] = [];
let mainTemp = 0;
if (CONFIG.enable_cpu_temps) {
const siTemps = await si.cpuTemperature();
const threadsPerCore = staticInfo.cpu.threads / staticInfo.cpu.cores;
temps = (await si.cpuTemperature()).cores.flatMap(temp =>
Array(threadsPerCore).fill(temp)
);
temps = siTemps.cores.flatMap(temp => Array(threadsPerCore).fill(temp));
mainTemp = siTemps.main; // AVG temp of all cores, in case no per-core data is found
}

return loads.map(({ load }, i) => ({
load,
temp: temps[i],
temp: temps[i] ?? mainTemp,
core: i,
}));
}
Expand Down

0 comments on commit 523e7a1

Please sign in to comment.