Use `k10temp-pci-00c3` sensor output instead of `asus_wmi_sensors-virtual-0` to read the CPU temperature because on the ASUS Prime x470 Pro the latter is buggy and can result in the UEFI fan control either slamming at 100% or not registering a temperature change at full load.
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
cache_dir=~/.cache/tmux
 | 
						|
cache_file=$cache_dir/system-info
 | 
						|
 | 
						|
# Make sure the output directory exists.
 | 
						|
if [ ! -d $cache_dir ]; then
 | 
						|
  mkdir -p $cache_dir
 | 
						|
fi
 | 
						|
 | 
						|
if sensors 'coretemp-isa-0000' &> /dev/null; then
 | 
						|
  function get_cpu_temp() {
 | 
						|
    sensors 'coretemp-isa-0000' | awk 'NR == 3 { print substr($4, 2) }'
 | 
						|
  }
 | 
						|
elif sensors 'k10temp-pci-00c3' &> /dev/null; then
 | 
						|
  function get_cpu_temp {
 | 
						|
    sensors 'k10temp-pci-00c3' | grep 'Tctl:' | awk '{ print $2 }'
 | 
						|
  }
 | 
						|
else
 | 
						|
  function get_cpu_temp {
 | 
						|
    echo 'N/A°C'
 | 
						|
  }
 | 
						|
fi
 | 
						|
 | 
						|
# Cleanup cache file when interrupted.
 | 
						|
trap '[ -f $cache_file ] && rm $cache_file; exit' INT
 | 
						|
trap '[ -f $cache_file ] && rm $cache_file; exit' TERM
 | 
						|
 | 
						|
while true; do
 | 
						|
  # Parse the current CPU load on all cores/threads.
 | 
						|
  cpu_load=`mpstat -P ALL -n 1 -u 1 -o JSON | \
 | 
						|
    jq '.sysstat.hosts[0].statistics[0]["cpu-load"][1:]|.[].idle' | \
 | 
						|
    awk '$idle ~ /[-.0-9]*/ { printf "%s", substr("█▇▆▅▄▃▂▁ ", int($idle / 11), 1) }'`
 | 
						|
  # Parse the current CPU package temperature.
 | 
						|
  cpu_temp=$(get_cpu_temp)
 | 
						|
  # Write to the cache file.
 | 
						|
  echo "$cpu_temp $cpu_load" > $cache_file
 | 
						|
done
 |