本脚本用于监控Nginx的连接数,Nginx所占用内存的总数,以及进程数。
#/bin/bash
host=`hostname`
ip=`ifconfig eth0 | grep ‘inet addr’|sed ‘s/.*addr://g’|sed ‘s/B.*//g’`
#监控nginx的连接数
http_req=`netstat -nat|grep -i “80″|wc -l `
time_stamp=`date “+%Y/%m/%d %T”`
if [ ${http_req} -ge 300 ];
then
echo “alert ==> ${host}@${ip}: http connection ${http_req} >= 300 @${time_stamp} ”
else
echo “${host}@${ip}: http connection ${http_req} @ ${time_stamp}”
fi
##监控nginx的进程
nginx_proc=`ps -C nginx –no-header | wc -l `
time_stamp=`date “+%Y/%m/%d %T”`
if [ ${nginx_proc} -ge 100 ]
then
echo “alert ==> ${host}@${ip}: nginx process ${nginx_proc} >= 100 @${time_stamp} ”
else
echo “${host}@${ip}: nginx process ${nginx_proc} @ ${time_stamp}”
fi
#监控nginx所占用的内存总数
nginx_mem=`top -b -n1 | grep nginx |gawk ‘{sum += $6}; END {print int(sum/1024)}’ `
time_stamp=`date “+%Y/%m/%d %T”`
if [ ${nginx_mem} -ge 500 ]
then
echo “alert ==> ${host}@${ip}: nginx memory usage ${nginx_mem} MB >= 500 @${time_stamp} ”
else
echo “${host}@${ip}: nginx memory ${nginx_mem}MB @ ${time_stamp}”
fi
阅读(2394) | 评论(0) | 转发(0) |