Chinaunix首页 | 论坛 | 博客
  • 博客访问: 158136
  • 博文数量: 42
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 377
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-01 11:18
个人简介

虔诚运维

文章分类

全部博文(42)

文章存档

2014年(42)

我的朋友

分类: LINUX

2014-07-23 15:25:41

转载:

该脚本针对网上已有解决方案(google一下nginx状态监控shell脚本),修改内存总数计算bug,修改字符错误。在CentOs5.7系统环境下测试可用。

1.  #/bin/bash

2.  host=`hostname`

3.  ip=`ifconfig eth0 | grep 'inet addr'|sed 's/.*addr://g'|sed 's/B.*//g'`

4.  #监控nginx的连接数

5.  http_req=`netstat -nat|grep -i "80"|wc -l `

6.  time_stamp=`date "+%Y/%m/%d %T"`

7.  if [ ${http_req} -ge 300 ];

8.  then

9.  echo "alert ==> ${host}@${ip}: http connection ${http_req} >= 300 @${time_stamp} "

10.else

11.echo "${host}@${ip}: http connection ${http_req} @ ${time_stamp}"

12.fi

13.##监控nginx的进程

14.nginx_proc=`ps -C nginx -no-header | wc -l `

15.time_stamp=`date "+%Y/%m/%d %T"`

16.if [ ${nginx_proc} -ge 100 ]

17.then

18.echo "alert ==> ${host}@${ip}: nginx process ${nginx_proc} >= 100 @${time_stamp} "

19.else

20.echo "${host}@${ip}: nginx process ${nginx_proc} @ ${time_stamp}"

21.fi

22.#监控nginx所占用的内存总数

23.nginx_mem=`top -b -n1 | grep nginx |gawk '{if($6~/m$/) {sum+=$6*1024} else {sum+=$6} }; END {print int(sum/1024)}' `

24.time_stamp=`date "+%Y/%m/%d %T"`

25.if [ ${nginx_mem} -ge 500 ]

26.then

27.echo "alert ==> ${host}@${ip}: nginx memory usage ${nginx_mem} MB >= 500 @${time_stamp} "

28.else

29.echo "${host}@${ip}: nginx memory ${nginx_mem}MB @ ${time_stamp}"

30.fi

 


阅读(2641) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~