-
Notifications
You must be signed in to change notification settings - Fork 64
/
monitor.sh
27 lines (20 loc) · 683 Bytes
/
monitor.sh
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
#!/bin/sh
cpu=$(awk '/^cpu/ {usage=($2+$4)*100/($2+$4+$5)} END{printf("%d\n", usage)}' /proc/stat)
[ $cpu -ge 80 ] && notify-send -u critical "High CPU usage: ${cpu}%"
free -m | while read Type Total Used Free _; do
if [ "$Type" = 'Mem:' ]; then
PCent=$((Used*100/Total))
[ $PCent -ge 80 ] && notify-send -u critical "High RAM usage: ${PCent}%"
fi
done
# Bourne POSIX-compliant approach.
df -P / | while read F1 _ _ _ F5 _; do
if ! [ "$F1" = 'Filesystem' ]; then
PCent=${F5%\%}
[ $PCent -ge 80 ] && notify-send -u critical "High DISK usage: ${PCent}%"
# In-case there are for some reason >1 matches.
break
fi
done
# In-case we're running in a cron job.
exit 0