1.在mysql端(zabbix客户端)修改监控mysql的参数
[root@db01 ~]# vim /etc/my.cnf
[mysql]
auto-rehash
user=用户名
password=密码
[mysqladmin]
user=用户名
password=密码
[root@db01 ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
UserParameter=mysql.status[*],echo
"show global status where Variable_name=‘$1‘;" |
/usr/local/mysql-5.6.28/bin/mysql -S /tmp/mysql.sock -N | awk ‘{print
$$2}‘
UserParameter=mysql.size[*],echo "select sum($(case "$3" in
both|"") echo "data_length+index_length";; data|index) echo
"$3_length";; free) echo "data_free";; esac)) from
information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where
table_schema=‘$1‘")$([[ "$2" = "all" || ! "$2" ]] || echo "and
table_name=‘$2‘");" | /usr/local/mysql-5.6.28/bin/mysql -S
/tmp/mysql.sock -N
UserParameter=mysql.ping,/usr/local/mysql-5.6.28/bin/mysqladmin -S /tmp/mysql.sock ping | grep -c alive
UserParameter=mysql.version,/usr/local/mysql-5.6.28/bin/mysql -S /tmp/mysql.sock -V
[root@db01 ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [ OK ]
Starting Zabbix agent: [ OK ]
[root@db01 ~]#
2.在zabbix服务端测试命令
[root@db02 ~]# zabbix_get -s mysql的IP地址 -k "mysql.version"
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
[root@db02 ~]# zabbix_get -s mysql的IP地址 -k "mysql.ping"
0
[root@db02 ~]#
3.在zabbix控制台要监控的主机上附加mysql模板
4.绘制的图形
本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1772671
原文地址:http://tongcheng.blog.51cto.com/6214144/1772671