-
Notifications
You must be signed in to change notification settings - Fork 1
/
ram
executable file
·39 lines (34 loc) · 1.22 KB
/
ram
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
#!/usr/bin/env sh
#
# Saumon i3blocks scripts
# ram (current ram usage with swap warning)
#
case $BLOCK_BUTTON in
2) gnome-system-monitor & ;; # middle click: show process manager
3) # right click: print top RAM eaters
ramUsed=$(free -h | tail -2 | head -1 | awk '{ print $3 " / " $2 }')
swapUsed=$(free -h | tail -2 | tail -1 | awk '{ print $3 " / " $2 }')
topEaters=$(ps aux --sort=-rss | tail -n +2 | head -n10 | awk '{ print $11 }' | sed 's:.*/::' | uniq)
dunstify -t 8000 -u low "RAM usage" "$ramUsed"
dunstify -t 8000 -u low "Swap usage" "$swapUsed"
dunstify -t 8000 -u low "Top RAM eaters" "$topEaters"
;;
esac
free=$(free | tail -2)
ramUsed=$(echo "$free" | head -1 | awk '{ print int($3 / $2 * 100) }')
swapUsed=$(echo "$free" | tail -1 | awk '{ print int($3 / $2 * 100) }')
if [ "$ramUsed" -ge 90 ]; then
color="#f44336"
elif [ "$ramUsed" -ge 85 ]; then
color="#ff9800"
else
color="#cccccc"
fi
if [ "$swapUsed" -ge 75 ]; then
swapPart="<span weight='bold' color='#f44336'> [S]</span>"
elif [ "$swapUsed" -ge 50 ]; then
swapPart="<span weight='bold' color='#ff9800'> [S]</span>"
else
swapPart=""
fi
printf "<span color='%s'> %s<small>%%</small></span>%s \n" "$color" "$ramUsed" "$swapPart"