Xtradb+Haproxy高可用数据库集群(四)集群zabbix监控篇
2015-08-12 18:21
399 查看
xtradb cluster集群zabbix监控
监控指标
官网参考地址:https://www.percona.com/doc/percona-xtradb-cluster/5.6/manual/monitoring.html 1、报警参数每个集群节点状态:wsrep_cluster_status != Primarywsrep_connected != ONwsrep_ready != ON 复制冲突过高wsrep_local_cert_failures
wsrep_local_bf_aborts 流量控制信息wsrep_flow_control_sent
wsrep_flow_control_recv 复制队列大小wsrep_local_recv_queue 2、长期图表收集参数队列大小wsrep_local_recv_queue
wsrep_local_send_queue 流量控制wsrep_flow_control_sent
wsrep_flow_control_recv 本节点进出交换数量wsrep_replicated
wsrep_received 进出交换的字节数wsrep_replicated_bytes
wsrep_received_bytes 复制冲突wsrep_local_cert_failures
Zabbix监控脚本
[root@yang-219 ~]# cat monit_xtradb.py
#!/usr/bin/python env #coding=utf-8 #time: 2015-8-12 #function: monit xtradb cluster status #author: yangr import re,time,os import commands ###variable 数据库及监控项变量定义区域 mysql_user='sstuser' mysql_pass='s3cret' mysql_host='localhost' mysql_port='3306' monit_message=''' wsrep_cluster_status wsrep_connected wsrep_ready wsrep_local_cert_failures wsrep_local_bf_aborts wsrep_flow_control_sent wsrep_flow_control_recv wsrep_local_recv_queue wsrep_local_recv_queue wsrep_local_send_queue wsrep_flow_control_sent wsrep_flow_control_recv wsrep_replicated wsrep_received wsrep_replicated_bytes wsrep_received_bytes wsrep_local_cert_failures wsrep_local_bf_aborts ''' monit_list=monit_message.split() ####zabbix 相关参数定义区域 zabbix_agent_file='/usr/local/zabbix/etc/zabbix_agentd.conf' zabbix_server=commands.getstatusoutput('''grep '^ServerActive' %s|awk -F[=] '{print $2}' '''%zabbix_agent_file)[1].strip() zabbix_hostname=commands.getstatusoutput('''grep '^Hostname' %s|awk -F[=] '{print $2}' '''%zabbix_agent_file)[1].strip() zabbix_server_port=10051 timestamp = int(time.time()) tmp_file_path='/tmp/xtradb_cluster_status.txt' zabbix_hostname='zabbix_server' zabbix_server='zabbix_server' ####end variable变量定义结束 #获取全局状态信息 status,global_status=commands.getstatusoutput(''' mysql -u%s -p%s -h%s -P%s -e 'show global status like "wsrep%%";' '''%(mysql_user,mysql_pass,mysql_host,mysql_port)) #print ''' mysql -u%s -p%s -h%s -P%s -e 'show global status like "wsrep%%";' '''%(mysql_user,mysql_pass,mysql_host,mysql_port) #print global_status global_status=global_status.split('\n') #print global_status #清空文件 with open(tmp_file_path,'wb') as f: f.write('') #循环要监控的指标 for i in monit_list: #循环状态列表,取出指标当前的值 for n in global_status: if "%s\t"%i in n: value=re.sub(r'.*\t','',n).strip() #print i,'value:',value #把值写入临时文件 with open(tmp_file_path,'ab') as f: f.write('%s %s %s %s\n'%(zabbix_hostname,i,timestamp,value)) #把临时文件通过zabbix_sender命令发送到server端 send_data_cmd='/usr/local/zabbix/bin/zabbix_sender -vv -z %s -p %s -T -i %s'%(zabbix_server,zabbix_server_port,tmp_file_path) print '/usr/local/zabbix/bin/zabbix_sender -vv -z %s -p %s -T -i %s'%(zabbix_server,zabbix_server_port,tmp_file_path) #print send_data_cmd os.popen(send_data_cmd)
脚本里monit_message对应的监控项,需要在zabbix服务器上添加对应的监控项,然后把这个脚本放到crontab里每分钟执行一次即可。
相关文章推荐
- Xtradb+Haproxy高可用数据库集群(四)集群zabbix监控篇
- oracle中使用impdp数据泵导入数据提示“ORA-31684:对象类型已经存在”错误的解决
- python 访问hbase数据库代码,乱写
- 创建mysql用户以及权限设置
- 修改 mysql root 用户的密码
- ubuntu10.04 安装oracle server 版 笔记
- JDBC连接SQL Server数据库
- WebX5 sqllite 增删改查
- Lock wait timeout exceeded数据库死锁问题
- 【工具设置】无人值守安装SQL Server 2008 R2
- mysql 分组总和求最大值 的两种方式
- MySQL____存储过程学习笔记
- 细小知识点之MySQL(二)
- mysql 查询使用*和具体字段的问题
- SQL SERVER简单的增,删,查,改 语句 多表关联查询 (去掉关键列查询)
- Redis集群的安装测试(伪分布模式 - 主从复制)
- 安装MySQL
- mysql 数据查询出排序中的最大值和最小值
- sqlserver 存储过程 try catch TRANSACTION (转)
- Linux中使用xmanager安装oracle数据库