nagios --redis 监控脚本
2013-04-18 14:49
381 查看
目前脚本可以监控 redis内存使用率,fork时间
脚本使用方法:
监控内存使用率
./check_redis.py -H 192.168.1.100 -p 6379 -C memuse -w 80 -c 90
监控上次fork消耗时间(通常redis在进行fork时,redis服务的响应会有影响)
./check_redis.py -H 192.168.1.100 -p 6379 -C fork -w 3 -c 5
cat check_redis.py
本文出自 “扫榻人” 博客,请务必保留此出处http://enable.blog.51cto.com/747951/1180708
脚本使用方法:
监控内存使用率
./check_redis.py -H 192.168.1.100 -p 6379 -C memuse -w 80 -c 90
监控上次fork消耗时间(通常redis在进行fork时,redis服务的响应会有影响)
./check_redis.py -H 192.168.1.100 -p 6379 -C fork -w 3 -c 5
cat check_redis.py
#!/bin/env python #-*-encoding=utf8-*- __author__ = 'songtao' import redis import sys import getopt def usage(): print """ -H 127.0.0.1 -p 6379 -C [memuse|fork] -w 50 -c 80 ./check_redis.py -H 127.0.0.1 -p 6379 -C memuse -c 80 -w 90 """ sys.exit(3) #def conn_redis(host,port): # r = redis.Redis(hosthost=host,portport=port) # if r.ping(): # r = redis.Redis(hosthost=host,portport=port) # return r # else: # print "can not connect!!" # sys.exit(0) #r = redis.Redis(hosthost=host,portport=port) warning = 80 critical = 90 def memused(): maxmem = r.config_get()['maxmemory'] usedmem = r.info()['used_memory'] result = float(usedmem) / float(maxmem) * 100 if result >=warning and result < critical: print "Warning!;mem_used:%.2f%%|mem_used:%.2f%%" % (result,result) sys.exit(1) elif result > critical: print "Critical!;mem_used:%.2f%%|mem_used:%.2f%%" % (result,result) sys.exit(2) else: print "OK!;mem_used:%.2f%%|mem_used:%.2f%%" % (result,result) sys.exit(0) def redis_fork(): fork_used = r.info()['latest_fork_usec'] / 1000 result = float(fork_used) / 1000 if result >=warning and result < critical: print "Warning!;latest_fork:%.2f%%|latest_fork:%.2f%%" % (result,result) sys.exit(1) elif result > critical: print "Critical!;latest_fork:%.2f%%|latest_fork:%.2f%%" % (result,result) sys.exit(2) else: print "OK!;latest_fork:%.2f%%|latest_fork:%.2f%%" % (result,result) sys.exit(0) if "__main__" == __name__: try: opts,args = getopt.getopt(sys.argv[1:],"h:H:p:C:w:c:") for opt,arg in opts: if opt in ("-h","--help"): usage() if opt in ("-H","--host"): host = arg if opt in ("-p","--port"): port = int(arg) if opt in ("-C","--command"): cmd = arg if opt in ("-w","--warning"): warning = float(arg) if opt in ("-c","--critical"): critical = float(arg) except: print "please check the host or opts" usage() sys.exit(3) # print opts # print args # print "host is %s ,port is %s,cmd is %s,warning is %s,critical is %s" % (host,port,cmd,warning,critical) try: r = redis.Redis(hosthost=host,portport=port) r.ping() except: print "redis can not connected or command is error" usage() sys.exit(3) if cmd == "memuse": memused() if cmd == "fork": redis_fork()
本文出自 “扫榻人” 博客,请务必保留此出处http://enable.blog.51cto.com/747951/1180708
相关文章推荐
- nagios监控redis端口、监控url接口告警脚本
- nagios监控redis内存使用情况脚本--shell实现
- nagios用监控dell服务器硬盘或scsi卡连接的盘阵的脚本
- Nagios监控内存脚本(include warning and critical)
- nagios监控slave(借助脚本)
- nagios 监控shell脚本
- centos nagios监控linux主机监控内存脚本
- 一键搭建nagios监控系统之一 脚本篇
- nagios通过脚本对系统进行定制监控
- nagios监控流量脚本
- Nagios监控WEB服务的脚本
- 懒人nagios页面监控脚本
- nagios监控解决Perl脚本问题
- Nagios搭建配置及监控脚本开发
- nagios监控mysql(借助脚本)
- nagios监控服务器磁盘空间的脚本
- 一键搭建nagios监控系统之二 脚本解释篇
- nagios自定义监控系统磁盘脚本
- linux-shell脚本,监控nginx,tomcat,redis,php-cli,磁盘状态
- 关于nagios监控系统添加主机和服务脚本