-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdwmblocks_systemstats
78 lines (59 loc) · 2.4 KB
/
dwmblocks_systemstats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
# Sensor info
echo "Available sensors:" > /tmp/dwmblocks_debug.log
sensors >> /tmp/dwmblocks_debug.log
echo "---" >> /tmp/dwmblocks_debug.log
CPU_TEMP=$(sensors | awk '
/^Tdie|^Package id|^Core 0|^CPU|^temp1/ {
gsub(/[+°C]/, "");
for (i=1; i<=NF; i++) {
if ($i ~ /^[0-9]+(\.[0-9]+)?$/) {
gsub(/\..*/, "", $i);
print $i;
exit;
}
}
}')
# Debug CPU temperature detection, if not found, return N/A
if [ -z "$CPU_TEMP" ]; then
# Try simpler pattern as fallback
CPU_TEMP=$(sensors | grep -E '^(Core 0|Package id 0|CPU)' | awk '{print $3}' | tr -d '+°C' | head -n1)
fi
[ -z "$CPU_TEMP" ] && CPU_TEMP="N/A"
echo "CPU_TEMP=$CPU_TEMP" >> /tmp/dwmblocks_debug.log
# Try different GPU temperature sensors (AMD and NVIDIA), if not found, return N/A
if command -v nvidia-smi >/dev/null 2>&1; then
# NVIDIA GPU
GPU_TEMP=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader)
else
# AMD GPU
GPU_TEMP=$(sensors | awk '/^edge|^junction/ {gsub(/\+/,""); gsub(/\..*/,"",$2); print $2}')
fi
[ -z "$GPU_TEMP" ] && GPU_TEMP="N/A"
# Try different fan sensors
FAN_SPEED=$(sensors | awk '/^fan|^cpu_fan/ {print $2" "$3}')
[ -z "$FAN_SPEED" ] && FAN_SPEED="N/A"
# Memory and CPU usage
MEM_USE=$(free -m | awk '/^Mem/ {printf "%.1f", ($3)/1024}')
CPU_USE=$(iostat -c | awk '/avg-cpu:/{getline; print "User CPU: "$1"%\n\nSystem CPU: "$3"%"}')
# Show warning icon if CPU or GPU temp are high
case $CPU_TEMP in
"N/A") COLOR="#d8dee9" && CPU_ICON=" ?" ;;
[7-9][6-9]|[8-9][0-9]|100) COLOR="#bf616a" && CPU_ICON="" ;; # Greater than 75
[6][6-9]|7[0-5]) COLOR="#ebcb8b" && CPU_ICON="" ;; # Between 66 and 75
*) COLOR="#a3be8c" && CPU_ICON="" ;; # 65 or below
esac
case $GPU_TEMP in
"N/A") GPU_ICON=" ?" ;;
[7-9][1-9]|[8-9][0-9]|100) GPU_ICON="" ;; # Greater than 71
[5][1-9]|70) GPU_ICON="" ;; # Between 51 and 70
*) GPU_ICON="" ;; # 50 or below
esac
# Send to bar
echo " $GPU_ICON $GPU_TEMP°C $CPU_ICON $CPU_TEMP°C ${MEM_USE}g"
# Clicking on bar
case $BLOCK_BUTTON in
1) setsid -w -f "$TERMINAL" -e htop ;;
3) notify-send -t 10000 -h string:bgcolor:$COLOR Stats "$CPU_USE\n\nGPU: $GPU_TEMP°C\n\nFan Speed: $FAN_SPEED" ;;
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac