argos-system/system.sh
2021-04-28 08:28:41 +00:00

87 lines
3 KiB
Bash
Executable file

#! /bin/bash
# shellcheck disable=SC2034
# <bitbar.title>system</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Tobias Schmidl</bitbar.author>
# <bitbar.author.github>schtobia</bitbar.author.github>
# <bitbar.desc>system monitor</bitbar.desc>
# <bitbar.image></bitbar.image>
# <bitbar.dependencies>python,requests</bitbar.dependencies>
# <bitbar.abouturl>https://gitlab.com/schtobia/argos-system/-/blob/master/system.sh</bitbar.abouturl>
PURPLE_GREEN_THEME=("#762a83" "#9970ab" "#c2a5cf" "#a6dba0" "#5aae61" "#1b7837")
RED_GREEN_THEME=("#d73027" "#fc8d59" "#fee08b" "#d9ef8b" "#91cf60" "#1a9850")
ORIGINAL_THEME=("#acacac" "#ff0101" "#cc673b" "#ce8458" "#6bbb15" "#0ed812")
COLORS=("${RED_GREEN_THEME[@]}")
LOADAVG=$(cut -d' ' -f 1 /proc/loadavg)
CORES=$(grep -c processor /proc/cpuinfo)
LOAD_PER_CORE=$(echo "${LOADAVG} 100 * ${CORES} / p" | dc)
case ${LOAD_PER_CORE} in
[0-9]|[0-4][0-9])
COLOR="${COLORS[5]}"
;;
[5-6][0-9])
COLOR="${COLORS[4]}"
;;
[7-8][0-9])
COLOR="${COLORS[3]}"
;;
[9][0-9]|10[0-9])
COLOR="${COLORS[2]}"
;;
1[1-9][0-9])
COLOR="${COLORS[1]}"
;;
*)
COLOR="${COLORS[0]}"
;;
esac
echo "${LOADAVG} | color=${COLOR}"
echo "------"
# shellcheck disable=SC2154
[ "${ARGOS_MENU_OPEN}" == "false" ] && exit 0;
echo "<span size=\"large\" font_weight=\"bold\">Disks</span>"
IFS=$'\n';
for a in $(df -h | sed -n '/\/snap/d;/% *\//p' | sort -n --reverse -k 5,5 | head -n 4); do echo "${a} | font=monospace | size=8 | trim=false"; done;
echo "------"
echo "<span size=\"large\" font_weight=\"bold\">Core speeds</span>"
LINE=$(for a in /sys/devices/system/cpu/cpufreq/policy*; do echo -n "$(($(< "${a}"/scaling_cur_freq)/1000))/$(($(< "${a}"/scaling_max_freq)/1000)) :: "; done;)
echo "${LINE%::*}| font=monospace | size=8"
echo "------"
echo "<span size=\"large\" font_weight=\"bold\">Temperature</span>"
# shellcheck disable=SC2044
LINE=$(for current_node in $(find /sys/devices -ipath '*hwmon*' -name 'temp*input'); \
do \
input_temp=$(< "${current_node}"); \
if [ "${input_temp}" -eq "${input_temp}" ] 2> /dev/null; \
then
input_name=$(< "${current_node%/*}"/name); \
[ -n "${input_name}" ] && echo -n "${input_name} "; \
echo -n "$((input_temp / 1000))"; \
input_crit=$(< "${current_node%input}"crit 2> /dev/null); \
[ "${input_crit}" -eq "${input_crit}" ] 2> /dev/null && echo -n "/$((input_crit / 1000))"; \
echo -n " :: "; \
fi; \
done)
echo "${LINE%::*} | font=monospace | size=8"
echo "------"
echo "<span size=\"large\" font_weight=\"bold\">top</span>"
( \
export LANG=C; \
for a in $(top -o TIME -bcn1 -w150 | grep -vi "\b[KkMmGg]ib\b" | head -n 10); do echo "${a} | font=monospace | size=8 | trim=false"; done; \
)
echo "------"
echo "<span size=\"large\" font_weight=\"bold\">dmesg</span>"
for a in $(dmesg --color=always -Tx | fold -w 160 -s - | tail -n 10); do echo "${a} | font=monospace | size=8"; done;
#df -h | sort -n --reverse -k 5,5