Chinaunix首页 | 论坛 | 博客
  • 博客访问: 271817
  • 博文数量: 188
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -30
  • 用 户 组: 普通用户
  • 注册时间: 2017-03-29 11:17
文章分类
文章存档

2013年(8)

2012年(5)

2011年(13)

2010年(26)

2009年(63)

2008年(20)

2007年(32)

2006年(21)

分类: 系统运维

2013-05-23 14:02:19

一、 check_memcache脚本

点击(此处)折叠或打开

  1. #!/bin/bash

  2. # echo "Usage:$0 -w num1 -c num2"
  3. #fi

  4. #DATE=`date +%Y-%m-%d`
  5. response=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' |awk '{print $4}'`

  6. connections=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' -e 'uptime' |grep curr_connections | awk '{print $3}'`

  7. cmd_get=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' -e 'uptime' |grep cmd_get | awk '{print $3+0}'`

  8. get_hits=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' -e 'uptime' |grep get_hits | awk '{print $3+0}'`

  9. limit_maxbytes=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' -e 'uptime' |grep limit_maxbytes | awk '{print $3/1024/1024}'`

  10. th=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' -e 'uptime' |grep threads | awk '{print $3+0}'`

  11. bytes=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' -e 'uptime' |grep bytes |grep -vn '_'|awk '{print $3/1024/1024}'`

  12. ci=`/usr/local/nagios/libexec/check_tcp -H localhost -p 11211 -E -s 'statsrnquitrn' -e 'uptime' |grep curr_items|awk '{print $3+0}'`

  13. hit_rate=`echo "$get_hits*100/$cmd_get"|bc`


  14. mem_percentage=`echo "scale=2;100*$bytes/$limit_maxbytes"|bc`


  15. if [ $hit_rate -gt $4 ];then
  16.    echo "OK - hit rate is $hit_rate |Hit_rate=$hit_rate; Response=$response; mem_percentage=$mem_percentage%; Used_mem=$bytes; limit_maxMem=$limit_maxbytes; curr_items=$ci; curr_connections=$connections"
  17.    exit 0

  18. fi

  19. if [ $hit_rate -lt $4 ] && [ $hit_rate -gt $2 ];then
  20.    echo "Warning - hit rate is $hit_rate |Hit_rate=$hit_rate; Response=$response; mem_percentage=$mem_percentage%; Used_mem=$bytes; limit_maxMem=$limit_maxbytes; curr_items=$ci; curr_connections=$connections"

  21.    exit 1

  22. fi

  23. if [ $hit_rate -lt $2 ];then
  24.    echo "Critical - hit rate is $hit_rate |Hit_rate=$hit_rate; Response=$response; mem_percentage=$mem_percentage%; Used_mem=$bytes; limit_maxMem=$limit_maxbytes; curr_items=$ci; curr_connections=$connections"

  25.    exit 2

  26. fi


二、运行结果如下:

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