從zabbix 2.2開始,zabbix官方已經(jīng)支持了mysql監(jiān)控锤灿,但是mysql監(jiān)控默認(rèn)是不可用的第股,需要經(jīng)過額外的設(shè)置才可以使用。
mysql服務(wù)器端
- 連接本機(jī)mysql吼拥,創(chuàng)建zabbix帳戶
> GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY 'monitor';
> FLUSH PRIVILEGES;
-
zabbix agent配置
# vim /etc/zabbix_agentd.conf Include=/etc/zabbix_agentd.conf.d/*.conf
-
配置zabbix agent連接mysql信息
# mkdir /etc/zabbix_agentd.conf.d # touch /etc/zabbix_agentd.conf.d/.my.cnf # vim /etc/zabbix_agentd.conf.d/.my.cnf [mysql] host=localhost user=zabbix password=monitor [mysqladmin] host=localhost user=zabbix password=monitor
-
配置zabbix agent獲取mysql數(shù)據(jù)
# touch /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf # vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf ### MySQL DB Infomation UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|awk '{print $$2}' UserParameter=mysql.variables[*],echo "show global variables where Variable_name='$1';"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|awk '{print $$2}' UserParameter=mysql.ping,mysqladmin --defaults-file=/etc/zabbix_agentd.conf.d/.my.cnf ping|grep -c alive UserParameter=mysql.version,echo "select version();"|mysql --defaults-file=/etc/zabbix_agentd.conf.d/.my.cnf -N #### MySQL Master Information UserParameter=mysql.master.Slave_count,echo "show slave hosts;"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|wc -l UserParameter=mysql.master.Binlog_file,echo "show master status;"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|awk '{print $1}'|awk -F. '{print $1}' UserParameter=mysql.master.Binlog_number,echo "show master status;"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|awk '{print $1}'|awk -F. '{print $2}' UserParameter=mysql.master.Binlog_position,echo "show master status;"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|awk '{print $2}' UserParameter=mysql.master.Binlog_count,echo "show binary logs;"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|wc -l UserParameter=mysql.master.Binlog_total_size,echo "show binary logs;"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf -N|awk '{sum+=$NF}END{print sum}' #### MySQL Slave Information UserParameter=mysql.slave.Seconds_Behind_Master,echo "show slave status\G"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf|grep "Seconds_Behind_Master"|awk '{print $2}' UserParameter=mysql.slave.Slave_IO_Running,echo "show slave status\G"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf|grep "Slave_IO_Running"|awk '{print $2}' UserParameter=mysql.slave.Slave_SQL_Running,echo "show slave status\G"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf|grep "Slave_SQL_Running"|awk '{print $2}' UserParameter=mysql.slave.Relay_Log_Pos,echo "show slave status\G"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf|grep "Relay_Log_Pos"|awk '{print $2}' UserParameter=mysql.slave.Exec_Master_Log_Pos,echo "show slave status\G"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf|grep "Exec_Master_Log_Pos"|awk '{print $2}' UserParameter=mysql.slave.Read_Master_Log_Pos,echo "show slave status\G"|mysql --defaults- file=/etc/zabbix_agentd.conf.d/.my.cnf|grep "Read_Master_Log_Pos"|awk '{print $2}' #### MySQL InnoDB Information #UserParameter=mysql.innodb[*],/etc/zabbix_agentd.conf.d/mysql_innodb_status.sh $1 ####MySQL MyISAM Information
/etc/zabbix_agentd.conf.d/.my.cnf
為Zabbix Agent連接MySQL的配置文件
mysql
和mysqladmin
命令需在系統(tǒng)默認(rèn)$PATH變量中倚聚,否則需要改為絕對路徑 -
重啟zabbix agent
# /etc/init.d/zabbix_agentd restart
zabbix web端
導(dǎo)入模板
添加模板到主機(jī)