#!/bin/bash base_dir=/opt war_processor="tomcat" jar_processor="manager-server.jar platform-server.jar platform-item.jar platform-shop.jar platform-task.jar platform-trade.jar platform-user.jar" IP_ADDR=`ifconfig |grep inet|awk -F "[: ]+" ‘{print $3}‘|head -n1` MALL_ADDR="[email protected]" #磁盘超过百分之80发送邮件告警 mem_used() { DISK_USED=`df -T |sed -n "2p" |awk ‘{print ($4/$3)*100}‘` DISK_percentage=80 if [ `expr "$DISK_USED > $DISK_percentage"` ] then echo "$IP_ADDR:当前硬盘使用率为$DISK_USED%" | mail -s "服务器硬盘监控告警" $MALL_ADDR fi } #内存使用率大于90%告警 disk_used() { mem_pused=`/usr/bin/free -m | sed -n ‘2p‘|awk ‘{ print ($3+$6)/$2*100}‘` #memory usage percentage percentage=90 #clean mem_cache 使用bc来进行比较,不然会报错 if [ $(echo "$mem_pused > $percentage"|bc) -eq 1 ] then echo "$IP_ADDR:当前内存使用率为$mem_pused%" | mail -s "服务器内存监控告警" $MALL_ADDR #echo "1qaz2wsx" |sudo -S sh /opt/shell/clean_mem_cache.sh fi } #进程检测 process() { for jar in $jar_processor do JAR_PROCESS=`ps -ef |grep $jar |grep -v grep |wc -l` if [ $JAR_PROCESS = 0 ] then echo "$IP_ADDR:$jar进程已停止,请确认是否正常" | mail -s "服务器应用进程监控告警" $MALL_ADDR fi done for war in $war_processor do WAR_PROCESS=`ps -ef |grep $war |grep -v grep |wc -l` if [ $JAR_PROCESS = 0 ] then echo "$IP_ADDR:$war进程已停止,请确认是否正常" | mail -s "服务器应用进程监控告警" $MALL_ADDR fi done } process mem_used disk_used
原文地址:https://www.cnblogs.com/python-cat/p/12015896.html
时间: 2024-10-10 16:14:08