falcon监控redis
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,falcon 结合脚本redis-monitor.py进行监控redis* * * * * python /usr/local/openfalcon-0.2/mymon/redis-monitor.
千家信息网最后更新 2025年02月02日falcon监控redis
falcon 结合脚本redis-monitor.py进行监控redis* * * * * python /usr/local/openfalcon-0.2/mymon/redis-monitor.py &> /usr/local/openfalcon-0.2/mymon/redis-monitor.logcat redis-monitor.py#注意修改配置项:_redis_cli,def __init__,insts_list,ip#!/bin/env python#-*- coding:utf-8 -*-import jsonimport timeimport socketimport osimport reimport sysimport commandsimport urllib2, base64class RedisStats: # 如果你是自己编译部署到redis,请将下面的值替换为你到redis-cli路径 _redis_cli = '/usr/local/bin/redis-cli' _stat_regex = re.compile(ur'(\w+):([0-9]+\.?[0-9]*)\r') def __init__(self, port='6379', passwd=None, host='127.0.0.1'): self._cmd = '%s -h %s -p %s info' % (self._redis_cli, host, port) if passwd not in ['', None]: self._cmd = '%s -h %s -p %s -a %s info' % (self._redis_cli, host, port, passwd) def stats(self): ' Return a dict containing redis stats ' info = commands.getoutput(self._cmd) #print info return dict(self._stat_regex.findall(info))def main(): ip = '192.168.1.1' #ip = socket.gethostname() timestamp = int(time.time()) step = 60 # inst_list中保存了redis配置文件列表,程序将从这些配置中读取port和password,建议使用动态发现的方法获得,如: # inst_list = [ i for i in commands.getoutput("find /etc/ -name 'redis*.conf'" ).split('\n') ] insts_list = [ '/etc/redis/redis.conf' ] p = [] monit_keys = [ ('connected_clients','GAUGE'), ('blocked_clients','GAUGE'), ('used_memory','GAUGE'), ('used_memory_rss','GAUGE'), ('mem_fragmentation_ratio','GAUGE'), ('total_commands_processed','COUNTER'), ('rejected_connections','COUNTER'), ('expired_keys','COUNTER'), ('evicted_keys','COUNTER'), ('keyspace_hits','COUNTER'), ('keyspace_misses','COUNTER'), ('keyspace_hit_ratio','GAUGE'), ] for inst in insts_list: port = commands.getoutput("sed -n 's/^port *\([0-9]\{4,5\}\)/\\1/p' %s" % inst) passwd = commands.getoutput("sed -n 's/^requirepass *\([^ ]*\)/\\1/p' %s" % inst) metric = "redis" endpoint = ip tags = 'port=%s' % port try: conn = RedisStats(port, passwd) stats = conn.stats() except Exception,e: continue for key,vtype in monit_keys: #一些老版本的redis中info输出的信息很少,如果缺少一些我们需要采集的key就跳过 if key not in stats.keys(): continue #计算命中率 if key == 'keyspace_hit_ratio': try: value = float(stats['keyspace_hits'])/(int(stats['keyspace_hits']) + int(stats['keyspace_misses'])) except ZeroDivisionError: value = 0 #碎片率是浮点数 elif key == 'mem_fragmentation_ratio': value = float(stats[key]) else: #其他的都采集成counter,int try: value = int(stats[key]) except: continue i = { 'Metric': '%s.%s' % (metric, key), 'Endpoint': endpoint, 'Timestamp': timestamp, 'Step': step, 'Value': value, 'CounterType': vtype, 'TAGS': tags } p.append(i) print json.dumps(p, sort_keys=True,indent=4) method = "POST" handler = urllib2.HTTPHandler() opener = urllib2.build_opener(handler) url = 'http://127.0.0.1:1998/v1/push' request = urllib2.Request(url, data=json.dumps(p) ) request.add_header("Content-Type",'application/json') request.get_method = lambda: method try: connection = opener.open(request) except urllib2.HTTPError,e: connection = e # check. Substitute with appropriate HTTP code. if connection.code == 200: print connection.read() else: print '{"err":1,"msg":"%s"}' % connectionif __name__ == '__main__': proc = commands.getoutput(' ps -ef|grep %s|grep -v grep|wc -l ' % os.path.basename(sys.argv[0])) sys.stdout.flush() if int(proc) < 5: main()
redis 进程监控
redis状态监控
监控
配置
信息
动态
命中率
建议
文件
方法
点数
版本
状态
碎片
程序
脚本
路径
进程
面的
utf-8
编译
输出
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发功能定义
课程名称数据库系统概论ppt
软件开发公司重要还是程序猿
济南凌基网络技术有限公司
智慧校园管理平台服务器
阿里云数据库研发
北京邮件大学网络技术研究院
语音会议软件开发的特殊性
油中组分PNOA数据库
用语句复制一个数据库
计算机网络技术需要画画嘛
数据库设计代做价格
降低云服务器的安全等级
crm数据库是哪里的
mac邮箱发件服务器
数据库怎么看网站
戒毒所网络安全管理岗位
宝鸡市网络安全中心
唱响新时代网络安全
东营商城软件开发公司有哪些
网络安全身份表达方式
电子网络技术
淄川物流竞价软件开发报价
软件开发qinggelt
计算机网络技术大数据专业
浙江道阳网络技术有限公司招聘
葵壤网络安全吗
不同内网地址不能访问文件服务器
北京通信软件开发标准
sntp服务器的意思