CentOS 6.3下Zabbix监控MySQL数据库参数

系统环境:CentOS 6.3 x64 

MySQL:    mysql-5.6.10

zabbix:  zabbix-2.06

一.修改mysql客户端zabbix_agentd.conf配置:


# vi /usr/local/etc/zabbix_agentd.conf

这里注意mysql账号密码与你的数据库账户需对应

末行添加如下内容:

-----------------

UserParameter=mysql.Ping,mysqladmin -uroot -p123456  ping|grep alive|wc -l

UserParameter=mysql.Threads,mysqladmin -uroot -p123456  status|cut -f3 -d":"|cut -f1 -d"Q"

UserParameter=mysql.Questions,mysqladmin -uroot -p123456  status|cut -f4 -d":"|cut -f1 -d"S"

UserParameter=mysql.Slowqueries,mysqladmin -uroot -p123456  status|cut -f5 -d":"|cut -f1 -d"O"

UserParameter=mysql.Qps,mysqladmin -uroot -p123456  status|cut -f9 -d":"


UserParameter=mysql.Slave_IO_State,if [ "$(mysql -uroot -p123456  -e "show slave status\G"| grep Slave_IO_Running|awk '{print $2}')" == "Yes" ];then echo 1; else echo 0;fi

UserParameter=mysql.Slave_SQL_State,if [ "$(mysql -uroot -p123456  -e "show slave status\G"| grep Slave_SQL_Running|awk '{print $2}')" == "Yes" ];then echo 1; else echo 0;fi


UserParameter=mysql.Key_buffer_size,mysql -uroot -p123456  -e "show variables like 'key_buffer_size';"| grep -v Value |awk '{print $2/1024^2}'

UserParameter=mysql.Key_reads,mysql -uroot -p123456  -e "show status like 'key_reads';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Key_read_requests,mysql -uroot -p123456  -e "show status like 'key_read_requests';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Key_cache_miss_rate,echo $(mysql -uroot -p123456  -e "show status like 'key_reads';"| grep -v Value |awk '{print $2}') $(mysql -uroot -p123456  -e "show status like 'key_read_requests';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/$2*100)}'

UserParameter=mysql.Key_blocks_used,mysql -uroot -p123456  -e "show status like 'key_blocks_used';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Key_blocks_unused,mysql -uroot -p123456  -e "show status like 'key_blocks_unused';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Key_blocks_used_rate,echo $(mysql -uroot -p123456  -e "show status like 'key_blocks_used';"| grep -v Value |awk '{print $2}') $(mysql -uroot -p123456  -e "show status like 'key_blocks_unused';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/($1+$2)*100)}'

UserParameter=mysql.Innodb_buffer_pool_size,mysql -uroot -p123456  -e "show variables like 'innodb_buffer_pool_size';"| grep -v Value |awk '{print $2/1024^2}'

UserParameter=mysql.Innodb_log_file_size,mysql -uroot -p123456  -e "show variables like 'innodb_log_file_size';"| grep -v Value |awk '{print $2/1024^2}'

UserParameter=mysql.Innodb_log_buffer_size,mysql -uroot -p123456  -e "show variables like 'innodb_log_buffer_size';"| grep -v Value |awk '{print $2/1024^2}'


UserParameter=mysql.Table_open_cache,mysql -uroot -p123456  -e "show variables like 'table_open_cache';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Open_tables,mysql -uroot -p123456  -e "show status like 'open_tables';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Opened_tables,mysql -uroot -p123456  -e "show status like 'opened_tables';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Open_tables_rate,echo $(mysql -uroot -p123456  -e "show status like 'open_tables';"| grep -v Value |awk '{print $2}') $(mysql -uroot -p123456  -e "show status like 'opened_tables';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/($1+$2)*100)}'

UserParameter=mysql.Table_open_cache_used_rate,echo $(mysql -uroot -p123456  -e "show status like 'open_tables';"| grep -v Value |awk '{print $2}') $(mysql -uroot -p123456  -e "show variables like 'table_open_cache';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/($1+$2)*100)}'

UserParameter=mysql.Thread_cache_size,mysql -uroot -p123456  -e "show variables like 'thread_cache_size';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Threads_cached,mysql -uroot -p123456  -e "show status like 'Threads_cached';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Threads_connected,mysql -uroot -p123456  -e "show status like 'Threads_connected';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Threads_created,mysql -uroot -p123456  -e "show status like 'Threads_created';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Threads_running,mysql -uroot -p123456  -e "show status like 'Threads_running';"| grep -v Value |awk '{print $2}'


UserParameter=mysql.Qcache_free_blocks,mysql -uroot -p123456  -e "show status like 'Qcache_free_blocks';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Qcache_free_memory,mysql -uroot -p123456  -e "show status like 'Qcache_free_memory';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Qcache_hits,mysql -uroot -p123456  -e "show status like 'Qcache_hits';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Qcache_inserts,mysql -uroot -p123456  -e "show status like 'Qcache_inserts';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Qcache_lowmem_prunes,mysql -uroot -p123456  -e "show status like 'Qcache_lowmem_prunes';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Qcache_not_cached,mysql -uroot -p123456  -e "show status like 'Qcache_not_cached';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Qcache_queries_in_cache,mysql -uroot -p123456  -e "show status like 'Qcache_queries_in_cache';"| grep -v Value |awk '{print $2}'

UserParameter=mysql.Qcache_total_blocks,mysql -uroot -p123456  -e "show status like 'Qcache_total_blocks';"| grep -v Value |awk '{print $2}'

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/739eb9297bf4277b95d3ba31eb0aa88e.html