小米的监控程序 open-open falcon 监控参数是不是没有人维护了

Open-Falcon 监控系统监控 MySQL/Redis/MongoDB 状态监控-爱编程
Open-Falcon 监控系统监控 MySQL/Redis/MongoDB 状态监控
Open-Falcon 是小米运维部开源的一款互联网企业级监控系统解决方案,具体的安装和使用说明请见官网:,是一款比较全的监控。而且提供各种API,只需要把数据按照规定给出就能出图,以及报警、集群支持等等。
1) MySQL 收集信息脚本(mysql_monitor.py)
#!/bin/env python
# -*- encoding: utf-8 -*-
from __future__ import division
import MySQLdb
import datetime
import time
import sys
import fileinput
import requests
import json
class MySQLMonitorInfo():
def __init__(self,host,port,user,password):
self.password = password
def stat_info(self):
m = MySQLdb.connect(host=self.host,user=self.user,passwd=self.password,port=self.port,charset='utf8')
query = "SHOW GLOBAL STATUS"
cursor = m.cursor()
cursor.execute(query)
Str_string = cursor.fetchall()
Status_dict = {}
for Str_key,Str_value in Str_string:
Status_dict[Str_key] = Str_value
cursor.close()
return Status_dict
except Exception, e:
print (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
Status_dict = {}
return Status_dict
def engine_info(self):
m = MySQLdb.connect(host=self.host,user=self.user,passwd=self.password,port=self.port,charset='utf8')
_engine_regex = re.compile(ur'(History list length) ([0-9]+\.?[0-9]*)\n')
query = "SHOW ENGINE INNODB STATUS"
cursor = m.cursor()
cursor.execute(query)
Str_string = cursor.fetchone()
a,b,c = Str_string
cursor.close()
return dict(_engine_regex.findall(c))
except Exception, e:
print (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
return dict(History_list_length=0)
if __name__ == '__main__':
open_falcon_api = 'http://192.168.200.86:1988/v1/push'
db_list= []
for line in fileinput.input():
db_list.append(line.strip())
for db_info in db_list:
host,port,user,password,endpoint,metric = db_info.split(',')
host,port,user,password,endpoint = db_info.split(',')
timestamp = int(time.time())
= "port=%s" %port
conn = MySQLMonitorInfo(host,int(port),user,password)
stat_info = conn.stat_info()
engine_info = conn.engine_info()
mysql_stat_list = []
monitor_keys = [
('Com_select','COUNTER'),
('Qcache_hits','COUNTER'),
('Com_insert','COUNTER'),
('Com_update','COUNTER'),
('Com_delete','COUNTER'),
('Com_replace','COUNTER'),
('MySQL_QPS','COUNTER'),
('MySQL_TPS','COUNTER'),
('ReadWrite_ratio','GAUGE'),
('Innodb_buffer_pool_read_requests','COUNTER'),
('Innodb_buffer_pool_reads','COUNTER'),
('Innodb_buffer_read_hit_ratio','GAUGE'),
('Innodb_buffer_pool_pages_flushed','COUNTER'),
('Innodb_buffer_pool_pages_free','GAUGE'),
('Innodb_buffer_pool_pages_dirty','GAUGE'),
('Innodb_buffer_pool_pages_data','GAUGE'),
('Bytes_received','COUNTER'),
('Bytes_sent','COUNTER'),
('Innodb_rows_deleted','COUNTER'),
('Innodb_rows_inserted','COUNTER'),
('Innodb_rows_read','COUNTER'),
('Innodb_rows_updated','COUNTER'),
('Innodb_os_log_fsyncs','COUNTER'),
('Innodb_os_log_written','COUNTER'),
('Created_tmp_disk_tables','COUNTER'),
('Created_tmp_tables','COUNTER'),
('Connections','COUNTER'),
('Innodb_log_waits','COUNTER'),
('Slow_queries','COUNTER'),
('Binlog_cache_disk_use','COUNTER')
for _key,falcon_type in monitor_keys:
if _key == 'MySQL_QPS':
_value = int(stat_info.get('Com_select',0)) + int(stat_info.get('Qcache_hits',0))
elif _key == 'MySQL_TPS':
_value = int(stat_info.get('Com_insert',0)) + int(stat_info.get('Com_update',0)) + int(stat_info.get('Com_delete',0)) + int(stat_info.get('Com_replace',0))
elif _key == 'Innodb_buffer_read_hit_ratio':
_value = round((int(stat_info.get('Innodb_buffer_pool_read_requests',0)) - int(stat_info.get('Innodb_buffer_pool_reads',0)))/int(stat_info.get('Innodb_buffer_pool_read_requests',0)) * 100,3)
except ZeroDivisionError:
_value = 0
elif _key == 'ReadWrite_ratio':
_value = round((int(stat_info.get('Com_select',0)) + int(stat_info.get('Qcache_hits',0)))/(int(stat_info.get('Com_insert',0)) + int(stat_info.get('Com_update',0)) + int(stat_info.get('Com_delete',0)) + int(stat_info.get('Com_replace',0))),2)
except ZeroDivisionError:
_value = 0
_value = int(stat_info.get(_key,0))
falcon_format = {
'Metric': '%s' % (_key),
'Endpoint': endpoint,
'Timestamp': timestamp,
'Step': step,
'Value': _value,
'CounterType': falcon_type,
'TAGS': tags
mysql_stat_list.append(falcon_format)
#_key : History list length
for _key,_value in
engine_info.items():
_key = "Undo_Log_Length"
falcon_format = {
'Metric': '%s' % (_key),
'Endpoint': endpoint,
'Timestamp': timestamp,
'Step': step,
'Value': int(_value),
'CounterType': "GAUGE",
'TAGS': tags
mysql_stat_list.append(falcon_format)
print json.dumps(mysql_stat_list,sort_keys=True,indent=4)
requests.post(open_falcon_api, data=json.dumps(mysql_stat_list))
指标说明:收集指标里的COUNTER表示每秒执行次数,GAUGE表示直接输出值。
&Undo_Log_Length
未清除的Undo事务数
&Com_select
&select/秒=QPS
&Com_insert
&insert/秒
&Com_update
&update/秒
&Com_delete
&delete/秒
&Com_replace
&replace/秒
&MySQL_QPS
&MySQL_TPS
&ReadWrite_ratio
&Innodb_buffer_pool_read_requests
&innodb buffer pool 读次数/秒
&Innodb_buffer_pool_reads
&Disk 读次数/秒
&Innodb_buffer_read_hit_ratio
&innodb buffer pool 命中率
&Innodb_buffer_pool_pages_flushed
&innodb buffer pool 刷写到磁盘的页数/秒
&Innodb_buffer_pool_pages_free
&innodb buffer pool 空闲页的数量
&Innodb_buffer_pool_pages_dirty
&innodb buffer pool 脏页的数量
&Innodb_buffer_pool_pages_data
&innodb buffer pool 数据页的数量
&Bytes_received
&接收字节数/秒
&Bytes_sent
&发送字节数/秒
&Innodb_rows_deleted
&innodb表删除的行数/秒
&Innodb_rows_inserted
&innodb表插入的行数/秒
&Innodb_rows_read
&innodb表读取的行数/秒
&Innodb_rows_updated&
&innodb表更新的行数/秒
&Innodb_os_log_fsyncs
&Redo Log fsync次数/秒&
&Innodb_os_log_written
&Redo Log 写入的字节数/秒
&Created_tmp_disk_tables
&创建磁盘临时表的数量/秒
&Created_tmp_tables
&创建内存临时表的数量/秒
&Connections
&连接数/秒
&Innodb_log_waits
&innodb log buffer不足等待的数量/秒
&Slow_queries
&慢查询数/秒
&Binlog_cache_disk_use
&Binlog Cache不足的数量/秒
使用说明:读取配置到都数据库列表执行,配置文件格式如下(mysqldb_list.txt):
&IP,Port,User,Password,endpoint
192.168.2.21,3306,root,123,mysql-21:3306
192.168.2.88,3306,root,123,mysql-88:3306
最后执行:
python mysql_monitor.py mysqldb_list.txt
2) Redis 收集信息脚本(redis_monitor.py)
#!/bin/env python
#-*- coding:utf-8 -*-
import json
import time
import redis
import requests
import fileinput
import datetime
class RedisMonitorInfo():
def __init__(self,host,port,password):
self.password = password
def stat_info(self):
r = redis.Redis(host=self.host, port=self.port, password=self.password)
stat_info = r.info()
return stat_info
except Exception, e:
print (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
return dict()
def cmdstat_info(self):
r = redis.Redis(host=self.host, port=self.port, password=self.password)
cmdstat_info = r.info('Commandstats')
return cmdstat_info
except Exception, e:
print (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
return dict()
if __name__ == '__main__':
open_falcon_api = 'http://192.168.200.86:1988/v1/push'
db_list= []
for line in fileinput.input():
db_list.append(line.strip())
for db_info in db_list:
host,port,password,endpoint,metric = db_info.split(',')
host,port,password,endpoint = db_info.split(',')
timestamp = int(time.time())
falcon_type = 'COUNTER'
= "port=%s" %port
conn = RedisMonitorInfo(host,port,password)
#查看各个命令每秒执行次数
redis_cmdstat_dict = {}
redis_cmdstat_list = []
cmdstat_info = conn.cmdstat_info()
for cmdkey in cmdstat_info:
redis_cmdstat_dict[cmdkey] = cmdstat_info[cmdkey]['calls']
for _key,_value in redis_cmdstat_dict.items():
falcon_format = {
'Metric': '%s' % (_key),
'Endpoint': endpoint,
'Timestamp': timestamp,
'Step': step,
'Value': int(_value),
'CounterType': falcon_type,
'TAGS': tags
redis_cmdstat_list.append(falcon_format)
#查看Redis各种状态,根据需要增删监控项,str的值需要转换成int
redis_stat_list = []
monitor_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'),
('keys_num','GAUGE'),
stat_info = conn.stat_info()
for _key,falcon_type in monitor_keys:
#计算命中率
if _key == 'keyspace_hit_ratio':
_value = round(float(stat_info.get('keyspace_hits',0))/(int(stat_info.get('keyspace_hits',0)) + int(stat_info.get('keyspace_misses',0))),4)*100
except ZeroDivisionError:
_value = 0
#碎片率是浮点数
elif _key == 'mem_fragmentation_ratio':
_value = float(stat_info.get(_key,0))
#拿到key的数量
elif _key == 'keys_num':
_value = 0
for i in range(16):
_key = 'db'+str(i)
_num = stat_info.get(_key)
_value += int(_num.get('keys'))
_key = 'keys_num'
#其他的都采集成counter,int
_value = int(stat_info[_key])
falcon_format = {
'Metric': '%s' % (_key),
'Endpoint': endpoint,
'Timestamp': timestamp,
'Step': step,
'Value': _value,
'CounterType': falcon_type,
'TAGS': tags
redis_stat_list.append(falcon_format)
load_data = redis_stat_list+redis_cmdstat_list
print json.dumps(load_data,sort_keys=True,indent=4)
requests.post(open_falcon_api, data=json.dumps(load_data))
指标说明:收集指标里的COUNTER表示每秒执行次数,GAUGE表示直接输出值。
&connected_clients
连接的客户端个数
&blocked_clients
被阻塞客户端的数量
&used_memory
&Redis分配的内存的总量
&used_memory_rss
&OS分配的内存的总量
&mem_fragmentation_ratio
&内存碎片率,used_memory_rss/used_memory
&total_commands_processed
&每秒执行的命令数,比较准确的QPS
&rejected_connections
&被拒绝的连接数/秒
&expired_keys
&过期KEY的数量/秒&
&evicted_keys
&被驱逐KEY的数量/秒
&keyspace_hits
&命中KEY的数量/秒
&keyspace_misses
&未命中KEY的数量/秒
&keyspace_hit_ratio
&KEY的命中率
&KEY的数量
&各种名字都执行次数/秒
使用说明:读取配置到都数据库列表执行,配置文件格式如下(redisdb_list.txt):
&IP,Port,Password,endpoint
192.168.1.56,7021,zhoujy,redis-56:7021
192.168.1.55,7021,zhoujy,redis-55:7021
最后执行:
python redis_monitor.py redisdb_list.txt
3) MongoDB 收集信息脚本(mongodb_monitor.py)
...后续添加
4)其他相关的监控(需要装上agent),比如下面的指标:
告警项触发条件备注
all(#3)&10
Redis服务器过载,处理能力下降
all(#3)&10
CPU idle过低,处理能力下降
df.bytes.free.percent
all(#3)&20
磁盘可用空间百分比低于20%,影响从库RDB和AOF持久化
mem.memfree.percent
all(#3)&15
内存剩余低于15%,Redis有OOM killer和使用swap的风险
mem.swapfree.percent
all(#3)&80
使用20% swap,Redis性能下降或OOM风险
net.if.out.bytes
网络出口流量超90MB,影响Redis响应
net.if.in.bytes
网络入口流量超90MB,影响Redis响应
disk.io.util
all(#3)&90
磁盘IO可能存负载,影响从库持久化和阻塞写
相关文档:
(redis monitor)
(redis monitor)
版权所有 爱编程 (C) Copyright 2012. . All Rights Reserved.
闽ICP备号-3
微信扫一扫关注爱编程,每天为您推送一篇经典技术文章。中国领先的IT技术网站
51CTO旗下网站
小米运维―互联网企业级监控系统实践(3)
监控系统是整个运维环节,乃至整个产品生命周期中最重要的一环,事前及时预警发现故障,事后提供翔实的数据用于追查定位问题。监控系统作为一个成熟的运维产品,业界有很多开源的实现可供选择。
作者:laiwei来源:简书| 09:21
Web portal
一个高效的portal,对于提升用户的&使用效率&,加成很大,平时大家都这么忙,能给各位SRE、Devs减轻一些负担,那是再好不过了。
group的管理页面,可以和服务树结合,机器进出服务树节点,相关的模板会自动关联或者解除。这样服务上下线,都不需要手动来变更监控,大大提高效率,降低遗漏和误报警。
open-falcon portal HostGroup
一个最简单的模板的例子,模板支持继承和策略覆盖,模板和host group绑定后,host group下的机器会自动应用该模板的所有策略。
open-falcon template
当然,也可以写一个简单的表达式,就能达到监控的目的,这对于那些endpoint不是机器名的场景非常方便。
open-falcon expression
添加一个表达式也是很简单的。
open-falcon add an expression
对于监控系统来讲,历史数据的存储和高效率查询,永远是个很难的问题!
数据量大:目前我们的监控系统,每个周期,大概有2000万次数据上报(上报周期为1分钟和5分钟两种,各占50%),一天24小时里,从来不会有业务低峰,不管是白天和黑夜,每个周期,总会有那么多的数据要更新。
写操作多:一般的业务系统,通常都是读多写少,可以方便的使用各种缓存技术,再者各类数据库,对于查询操作的处理效率远远高于写操作。而监控系统恰恰相反,写操作远远高于读。每个周期几千万次的更新操作,对于常用数据库(MySQL、postgresql、mongodb)都是无法完成的。
高效率的查:我们说监控系统读操作少,是说相对写入来讲。监控系统本身对于读的要求很高,用户经常会有查询上百个meitric,在过去一天、一周、一月、一年的数据。如何在1秒内返回给用户并绘图,这是一个不小的挑战。
open-falcon在这块,投入了较大的精力。我们把数据按照用途分成两类,一类是用来绘图的,一类是用户做数据挖掘的。
对于绘图的数据来讲,查询要快是关键,同时不能丢失信息量。对于用户要查询100个metric,在过去一年里的数据时,数据量本身就在那里了,很难1秒之类能返回,另外就算返回了,前端也无法渲染这么多的数据,还得采样,造成很多无谓的消耗和浪费。我们参考rrdtool的理念,在数据每次存入的时候,会自动进行采样、归档。我们的归档策略如下,历史数据保存5年。同时为了不丢失信息量,数据归档的时候,会按照平均值采样、最大值采样、最小值采样存三份。
//&1分钟一个点存&12小时&c.RRA(&AVERAGE&,&0.5,&1,&720)&&//&5m一个点存2d&c.RRA(&AVERAGE&,&0.5,&5,&576)&c.RRA(&MAX&,&0.5,&5,&576)&c.RRA(&MIN&,&0.5,&5,&576)&&//&20m一个点存7d&c.RRA(&AVERAGE&,&0.5,&20,&504)&c.RRA(&MAX&,&0.5,&20,&504)&c.RRA(&MIN&,&0.5,&20,&504)&&//&3小时一个点存3个月&c.RRA(&AVERAGE&,&0.5,&180,&766)&c.RRA(&MAX&,&0.5,&180,&766)&c.RRA(&MIN&,&0.5,&180,&766)&&//&1天一个点存5year&c.RRA(&AVERAGE&,&0.5,&720,&730)&c.RRA(&MAX&,&0.5,&720,&730)&c.RRA(&MIN&,&0.5,&720,&730)&
对于原始数据,transfer会打一份到hbase,也可以直接使用opentsdb,transfer支持往opentsdb写入数据。
Committers
laiwei: /laiwei 来炜没睡醒@微博 / hellolaiwei@微信
秦晓辉: /ulricqin Ulricqin@微博 cnperl@微信
Contributors
近期我们会把绝大数的组件整理到 /open-falcon ,
期待大家一起贡献,推动,做最开放、最好用的企业级监控系统。
metric的聚合
环比、同比报警判定
流量的突升突降判定
【编辑推荐】
【责任编辑: TEL:(010)】
大家都在看猜你喜欢
专题专题专题原创专题
24H热文一周话题本月最赞
讲师:22人学习过
讲师:7人学习过
讲师:12人学习过
精选博文论坛热帖下载排行
程序设计实践并不只是写代码。程序员必须评论各种折衷方案,在许多可能性之中做出选择、排除错误、做测试和改进程序性能,还要维护自己或其...
订阅51CTO邮刊

我要回帖

更多关于 open falcon监控进程 的文章

 

随机推荐