• linux主机内存告警shell脚本


    #!/bin/sh
    
    ramusage=$(free | awk '/Mem/{printf("RAM Usage: %.2f
    "), $3/$2*100}'| awk '{print $3}')
    
    if [ "$ramusage" > 20 ]; then
      SUBJECT="ATTENTION: Memory Utilization is High on $(hostname) at $(date)"
      MESSAGE="/tmp/Mail.out"
      TO="2daygeek@gmail.com"
      echo "Memory Current Usage is: $ramusage%" >> $MESSAGE
      echo "" >> $MESSAGE
      echo "------------------------------------------------------------------" >> $MESSAGE
      echo "Top Memory Consuming Process Using top command" >> $MESSAGE
      echo "------------------------------------------------------------------" >> $MESSAGE
      echo "$(top -b -o +%MEM | head -n 20)" >> $MESSAGE
      echo "" >> $MESSAGE
      echo "------------------------------------------------------------------" >> $MESSAGE
      echo "Top Memory Consuming Process Using ps command" >> $MESSAGE
      echo "------------------------------------------------------------------" >> $MESSAGE
      echo "$(ps -eo pid,ppid,%mem,%Memory,cmd --sort=-%mem | head)" >> $MESSAGE
      mail -s "$SUBJECT" "$TO" < $MESSAGE
      rm /tmp/Mail.out
    fi
    
    # crontab -e
    # */5 * * * * /bin/bash /opt/scripts/memory-alert.sh
    
    # /usr/bin/free | awk '/Mem/{printf("RAM Usage: %.2f%
    "), $3/$2*100}' |  awk '{print $3}' | awk '{ if($1 > 20) print $0;}' | mail -s "High Memory Alert" 1103324414@qq.com
    
  • 相关阅读:
    hdu 2604 Queuing(矩阵快速幂乘法)
    hdu 5591 ZYB's Game
    hdu 5590 ZYB's Biology
    CodeForces
    uva 193 Graph Coloring(图染色 dfs回溯)
    uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)
    CSU
    hdu 5115 Dire Wolf(区间dp)
    腾讯装扮下拉选项卡特效(QQ空间)
    楼梯式定位导航系统
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/11640322.html
Copyright © 2020-2023  润新知