Xtradb+Haproxy高可用數據庫集羣(四)集羣zabbix監控篇

xtradb cluster集羣zabbix監控

監控指標

官網參考地址:

https://www.percona.com/doc/percona-xtradb-cluster/5.6/manual/monitoring.html

 

1、報警參數

每個集羣節點狀態:

wsrep_cluster_status != Primary

wsrep_connected != ON

wsrep_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

wsrep_local_bf_aborts

 

 

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裏每分鐘執行一次即可。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章