system-stats fix for intel cpu
This commit is contained in:
parent
eefab33f76
commit
0069463069
1 changed files with 25 additions and 12 deletions
|
|
@ -113,7 +113,7 @@ get_cpu_temp() {
|
||||||
if [[ -f "$dir/name" ]]; then
|
if [[ -f "$dir/name" ]]; then
|
||||||
local name
|
local name
|
||||||
name=$(<"$dir/name")
|
name=$(<"$dir/name")
|
||||||
# Check for supported sensor types (matches Zig code).
|
# Check for supported sensor types.
|
||||||
if [[ "$name" == "coretemp" || "$name" == "k10temp" ]]; then
|
if [[ "$name" == "coretemp" || "$name" == "k10temp" ]]; then
|
||||||
TEMP_SENSOR_PATH=$dir
|
TEMP_SENSOR_PATH=$dir
|
||||||
TEMP_SENSOR_TYPE=$name
|
TEMP_SENSOR_TYPE=$name
|
||||||
|
|
@ -131,15 +131,29 @@ get_cpu_temp() {
|
||||||
|
|
||||||
# --- Get temp based on sensor type ---
|
# --- Get temp based on sensor type ---
|
||||||
if [[ "$TEMP_SENSOR_TYPE" == "coretemp" ]]; then
|
if [[ "$TEMP_SENSOR_TYPE" == "coretemp" ]]; then
|
||||||
# For Intel 'coretemp', average all core temperatures.
|
# For Intel 'coretemp', average all available temperature sensors.
|
||||||
# find gets all temp inputs, cat reads them, and awk calculates the average.
|
local total_temp=0
|
||||||
# The value is in millidegrees Celsius, so we divide by 1000.
|
local sensor_count=0
|
||||||
find "$TEMP_SENSOR_PATH" -type f -name 'temp*_input' -print0 | xargs -0 cat | awk '
|
|
||||||
{ total += $1; count++ }
|
# Use a for loop with a glob to iterate over all temp input files.
|
||||||
END {
|
# This is more efficient than 'find' for this simple case.
|
||||||
if (count > 0) print int(total / count / 1000);
|
for temp_file in "$TEMP_SENSOR_PATH"/temp*_input; do
|
||||||
else print 0;
|
# The glob returns the pattern itself if no files match,
|
||||||
}'
|
# so we must check if the file actually exists.
|
||||||
|
if [[ -f "$temp_file" ]]; then
|
||||||
|
total_temp=$((total_temp + $(<"$temp_file")))
|
||||||
|
sensor_count=$((sensor_count + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if (( sensor_count > 0 )); then
|
||||||
|
# Use awk for the final division to handle potential floating point numbers
|
||||||
|
# and convert from millidegrees to integer degrees Celsius.
|
||||||
|
awk -v total="$total_temp" -v count="$sensor_count" 'BEGIN { print int(total / count / 1000) }'
|
||||||
|
else
|
||||||
|
# If no sensor files were found, return 0.
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
|
||||||
elif [[ "$TEMP_SENSOR_TYPE" == "k10temp" ]]; then
|
elif [[ "$TEMP_SENSOR_TYPE" == "k10temp" ]]; then
|
||||||
# For AMD 'k10temp', find the 'Tctl' sensor, which is the control temperature.
|
# For AMD 'k10temp', find the 'Tctl' sensor, which is the control temperature.
|
||||||
|
|
@ -163,7 +177,6 @@ get_cpu_temp() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# --- Main Loop ---
|
# --- Main Loop ---
|
||||||
# This loop runs indefinitely, gathering and printing stats.
|
# This loop runs indefinitely, gathering and printing stats.
|
||||||
while true; do
|
while true; do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue