mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
Fix: Armbianmonitor: Print the CPU frequency correctly without privileges (#4823)
* Type: Remove trailing spaces * Fix: Print the CPU frequency correctly without privileges.
This commit is contained in:
@@ -26,22 +26,22 @@
|
||||
# and provides a proposal for /etc/armbianmonitor/disks.conf
|
||||
# when a new disk is found.
|
||||
#
|
||||
# In case monitoring should be activated the following file
|
||||
# will be created: /etc/armbianmonitor/start-monitoring. If
|
||||
# debug output has been chosen, then DEBUG will be written to
|
||||
# In case monitoring should be activated the following file
|
||||
# will be created: /etc/armbianmonitor/start-monitoring. If
|
||||
# debug output has been chosen, then DEBUG will be written to
|
||||
# the file.
|
||||
#
|
||||
# The script will install smartmontools/gdisk if not already
|
||||
# installed and patches smartmontools' update-smart-drivedb
|
||||
# installed and patches smartmontools' update-smart-drivedb
|
||||
# script if necessary. For disks the 'device model' will be
|
||||
# shown but internally we rely always on the GUID. This is the
|
||||
# key for entry in /etc/armbianmonitor/disks.conf
|
||||
#
|
||||
# When the script exits and the user activated monitoring it
|
||||
# recommends doing a restart since on the next reboot the
|
||||
# setup-armbian-monitoring-environment script will configure
|
||||
# monitoring sources and decides based on the existence and
|
||||
# contents of /etc/armbianmonitor/start-monitoring whether
|
||||
# setup-armbian-monitoring-environment script will configure
|
||||
# monitoring sources and decides based on the existence and
|
||||
# contents of /etc/armbianmonitor/start-monitoring whether
|
||||
# rpimonitord should be started or not.
|
||||
#
|
||||
# The format of /etc/armbianmonitor/disks.conf is as follows:
|
||||
@@ -54,21 +54,22 @@
|
||||
# F8D372DC-63DB-494B-B802-87DC47FAD4E1:Samsung EVO:sat::199: # SSD in USB enclosure
|
||||
#
|
||||
# - GUID is the GUID as determined by gdisk
|
||||
# - 'Name': The name as it will later be shown in RPi-Monitor, defaults to
|
||||
# - 'Name': The name as it will later be shown in RPi-Monitor, defaults to
|
||||
# the 'device model' read out through smartctl but can be changed to
|
||||
# be more significant (beware that this string must contain colons!)
|
||||
# - "smartctl prefix" can be empty or should be the the necessary prefix for
|
||||
# USB disks, eg. '-d sat' or '-d usbjmicron' and so on -- please have a
|
||||
# - "smartctl prefix" can be empty or should be the the necessary prefix for
|
||||
# USB disks, eg. '-d sat' or '-d usbjmicron' and so on -- please have a
|
||||
# look at https://www.smartmontools.org/wiki/Supported_USB-Devices
|
||||
# - "temp call" when being omitted indicates that hddtemp should be used.
|
||||
# Otherwise it should contain the complete command line ('DISK' will be
|
||||
# dynamically replaced by the device node when the actual monitoring
|
||||
# - "temp call" when being omitted indicates that hddtemp should be used.
|
||||
# Otherwise it should contain the complete command line ('DISK' will be
|
||||
# dynamically replaced by the device node when the actual monitoring
|
||||
# happens), for example:
|
||||
# /sbin/hdparm -C DISK | grep -Eq "standby|sleeping" || /usr/sbin/smartctl -d sat -a DISK | awk -F" " '/Temperature_Cel/ {printf $10}'
|
||||
# /sbin/hdparm -C DISK | grep -Eq "standby|sleeping" || \
|
||||
# /usr/sbin/smartctl -d sat -a DISK | awk -F" " '/Temperature_Cel/ {printf $10}'
|
||||
# - 'CRC attribute': The decimal value of the S.M.A.R.T. attribute that
|
||||
# is used to store the count of checksum errors between disk and host
|
||||
# is used to store the count of checksum errors between disk and host
|
||||
# controller (might be omitted if the drive doesn't support it)
|
||||
# - 'LCC attribute': The decimal value of the S.M.A.R.T. attribute that
|
||||
# - 'LCC attribute': The decimal value of the S.M.A.R.T. attribute that
|
||||
# should contain the load cycle counter value (might be omitted
|
||||
# if the drive doesn't support it)
|
||||
#
|
||||
@@ -94,14 +95,14 @@ Main() {
|
||||
LRED='\e[0;91m'
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
[ $# -eq 0 ] && (DisplayUsage ; exit 0)
|
||||
|
||||
|
||||
ParseOptions "$@"
|
||||
|
||||
exit 0
|
||||
PreRequisits
|
||||
|
||||
|
||||
# check whether user runs rpimonitord on his own or we activated it
|
||||
if [ -f /etc/armbianmonitor/start-monitoring ]; then
|
||||
# we should already provide monitoring, check whether DEBUG
|
||||
@@ -109,12 +110,12 @@ Main() {
|
||||
ArmbianMonitoring=TRUE
|
||||
read -r DebugMode </etc/armbianmonitor/start-monitoring 2>/dev/null
|
||||
fi
|
||||
|
||||
|
||||
# check whether rpimonitord is running and compare with ${ArmbianMonitoring}
|
||||
# In case the user chose to run rpimonitord on his own, we skip the config
|
||||
# part and only output disk info
|
||||
:
|
||||
|
||||
|
||||
# check available disk devices
|
||||
CheckDisks
|
||||
} # Main
|
||||
@@ -322,7 +323,7 @@ MonitorMode() {
|
||||
|
||||
# Allow armbianmonitor to return back to armbian-config
|
||||
trap "echo ; exit 0" 0 1 2 3 15
|
||||
|
||||
|
||||
# Try to renice to 19 to not interfere with OS behaviour
|
||||
renice 19 $BASHPID >/dev/null 2>&1
|
||||
|
||||
@@ -339,23 +340,19 @@ MonitorMode() {
|
||||
SleepInterval=${interval:-5}
|
||||
|
||||
Sensors="/etc/armbianmonitor/datasources/"
|
||||
if [ -f /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq ]; then
|
||||
DisplayHeader="Time big.LITTLE load %cpu %sys %usr %nice %io %irq"
|
||||
CPUs=biglittle
|
||||
elif [ -f /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq ]; then
|
||||
if [ -f /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq ]; then
|
||||
DisplayHeader="Time CPU_cl0/CPU_cl1 load %cpu %sys %usr %nice %io %irq"
|
||||
CPUs=dual_cluster
|
||||
echo "Two CPU clusters are available for monitoring"
|
||||
elif [ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
|
||||
DisplayHeader="Time CPU load %cpu %sys %usr %nice %io %irq"
|
||||
CPUs=normal
|
||||
else
|
||||
DisplayHeader="Time CPU n/a load %cpu %sys %usr %nice %io %irq"
|
||||
CPUs=notavailable
|
||||
fi
|
||||
# Set freq output to --- if non-privileged. Overwrites settings above.
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "Running unprivileged. CPU frequency will not be displayed."
|
||||
CPUs=notavailable
|
||||
fi
|
||||
|
||||
[ -f "${Sensors}/soctemp" ] && DisplayHeader="${DisplayHeader} CPU" || SocTemp='n/a'
|
||||
[ -f "${Sensors}/soctemp" ] && DisplayHeader="${DisplayHeader} Tcpu" || SocTemp='n/a'
|
||||
[ -f "${Sensors}/pmictemp" ] && DisplayHeader="${DisplayHeader} PMIC" || PMICTemp='n/a'
|
||||
DCIN=$(CheckDCINVoltage)
|
||||
[ -f "${DCIN}" ] && DisplayHeader="${DisplayHeader} DC-IN" || DCIN='n/a'
|
||||
@@ -370,7 +367,7 @@ MonitorMode() {
|
||||
if [ "$c" == "m" ]; then
|
||||
let Counter++
|
||||
if [ ${Counter} -eq 15 ]; then
|
||||
printf "%s" "$DisplayHeader"
|
||||
printf "\n\n%s" "$DisplayHeader"
|
||||
Counter=0
|
||||
fi
|
||||
elif [ "$c" == "s" ]; then
|
||||
@@ -384,20 +381,20 @@ MonitorMode() {
|
||||
fi
|
||||
LoadAvg=$(cut -f1 -d" " </proc/loadavg)
|
||||
case ${CPUs} in
|
||||
biglittle)
|
||||
BigFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq) 2>/dev/null
|
||||
LittleFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) 2>/dev/null
|
||||
dual_cluster)
|
||||
Cluster1=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq) 2>/dev/null
|
||||
Cluster0=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) 2>/dev/null
|
||||
ProcessStats
|
||||
printf "\n%s: %4s/%4sMHz %5s %s" "$(date "+%H:%M:%S")" "$BigFreq" "$LittleFreq" "$LoadAvg" "$procStats"
|
||||
printf "\n%s %4s/%4s MHz %5s %s" "$(date "+%H:%M:%S")" "$Cluster0" "$Cluster1" "$LoadAvg" "$procStats"
|
||||
;;
|
||||
normal)
|
||||
CpuFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) 2>/dev/null
|
||||
ProcessStats
|
||||
printf "\n%s: %4sMHz %5s %s" "$(date "+%H:%M:%S")" "$CpuFreq" "$LoadAvg" "$procStats"
|
||||
printf "\n%s %4s MHz %5s %s" "$(date "+%H:%M:%S")" "$CpuFreq" "$LoadAvg" "$procStats"
|
||||
;;
|
||||
notavailable)
|
||||
ProcessStats
|
||||
printf "\n%s: --- %5s %s" "$(date "+%H:%M:%S")" "$LoadAvg" "$procStats"
|
||||
printf "\n%s --- %5s %s" "$(date "+%H:%M:%S")" "$LoadAvg" "$procStats"
|
||||
;;
|
||||
esac
|
||||
if [ "X${SocTemp}" != "Xn/a" ]; then
|
||||
@@ -405,14 +402,14 @@ MonitorMode() {
|
||||
if [ ${SocTemp} -ge 1000 ]; then
|
||||
SocTemp=$(awk '{printf ("%0.1f",$1/1000); }' <<<${SocTemp})
|
||||
fi
|
||||
printf " %4s °C" "$SocTemp"
|
||||
printf " %4s °C" "$SocTemp"
|
||||
fi
|
||||
if [ "X${PMICTemp}" != "Xn/a" ]; then
|
||||
read -r PMICTemp <"${Sensors}/pmictemp"
|
||||
if [ ${PMICTemp} -ge 1000 ]; then
|
||||
PMICTemp=$(awk '{printf ("%0.1f",$1/1000); }' <<<${PMICTemp})
|
||||
fi
|
||||
printf " %4s °C" "$PMICTemp"
|
||||
printf " %4s °C" "$PMICTemp"
|
||||
fi
|
||||
if [ "X${DCIN}" != "Xn/a" ]; then
|
||||
case "${DCIN##*/}" in
|
||||
@@ -427,7 +424,8 @@ MonitorMode() {
|
||||
esac
|
||||
printf " %5sV" "$DCINvoltage"
|
||||
fi
|
||||
[ "X${CoolingState}" != "Xn/a" ] && printf " %d/%d" "$(cat /sys/devices/virtual/thermal/cooling_device0/cur_state)" "$(cat /sys/devices/virtual/thermal/cooling_device0/max_state)"
|
||||
[ "X${CoolingState}" != "Xn/a" ] && \
|
||||
printf " %d/%d" "$(cat /sys/devices/virtual/thermal/cooling_device0/cur_state)" "$(cat /sys/devices/virtual/thermal/cooling_device0/max_state)"
|
||||
[ "$c" == "s" ] && sleep 0.3 || sleep ${SleepInterval}
|
||||
done
|
||||
} # MonitorMode
|
||||
|
||||
Reference in New Issue
Block a user