今天我来分享一下如何用zabbix自带的模板监控mysql
首先模板官方帮我们建好了,配置文件也写好了,我们只需要稍作配置即可使用
先配置好与服务器的连接并将主机添加到zabbix后台,此操作略过
配置mysql和mysqladmin免密码登陆
[client]
host=localhost
user = root
password = Aa123456
port = 3306
socket = /usr/local/mysql/mysql.sock
[mysqladmin]
host = localhost
user = root
password = Aa123456
port = 3306
socket = /usr/local/mysql/mysql.sock
修改userparameter_mysql.conf
注意这里修改的是my.cnf
配置文件的路径,请以实际为准
sed -i 's@/var/lib/zabbix@/usr/local/mysql/conf@g' /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
修改后的结果为:
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/usr/local/mysql/conf mysql -N | awk '{print $$2}'
UserParameter=mysql.size[*],bash -c '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\"");" | HOME=/usr/local/mysql/conf mysql -N'
UserParameter=mysql.ping,HOME=/usr/local/mysql/conf mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V
此时可又重启zabbix-agent
用又下命令测度,如果返回1表示配置成功
zabbix_get -s 10.168.204.80 -p 10050 -k mysql.ping
注意:如果测试的时候报错:
sh: mysql: command not found,sh: mysqladmin: command not found
修改userparameter_mysql.conf
中mysql
,mysqladmin
命令的路径,使用绝对路径。
配置完成后,在zabbix为主机套上模板即可
登陆zabbix后台
Configuration—Hosts—<主机>—Tempaltes,搜索MySQL,添加弹出的模板,然后更新
Monitoring—Graphs,选择组,然后选择host及展示的图形