Memory monitoring, automatic email alert
-
[Shell requirements]
Use the shell to write a memory monitoring script, using more than 80% of concurrent email alerts -
[Shell idea]
1. Idea: free
free -mtotal used free shared buff/cache available Mem: 3770 219 3170 11 381 3325 Swap: 2047 0 2047
##Mem: An overview table of memory usage.
##totel: The total physical memory unit of the machine is: M
##used: Used memory.
##free: Free physical memory.
2. Calculate the percentage
3. Compare and make judgments
-
[Shell configuration]
#!/bin/bash A=`free -m | grep "^Mem" | awk '{print $2}'` B=`free -m | grep "^Mem" | awk '{print $3}'` C=`free -m | grep "^Mem" | awk '{print $4}'` D=`free -m | awk '/Mem/ {print int($3/$2*100)}'` if [ $D -gt 1 ];then /opt/sendEmail.sh [email protected] "内存警告" "总内存为:$A M 已使用内存:$B M 空间内存:$C M 内存使用率已达$D % , 请尽快处理" #####xxxxxxxxx填写想发送的QQ fi
——————————————————————————————————————
This is the end, thanks for watching