标签:
本身zabbix-agent没有提供对mysql监控的key,所以需要自定义key来应用这个模板
默认的模板有以下三类
mysql.status[var]
mysql.ping
mysql.version
MySQL的监控就是用show status命令查看相关的参数,取值
在agent端编写key的监控脚本
# vim /usr/local/zabbix/scripts/mysql.status.sh
#!/bin/bash
mysql=$(which mysql)
var=$1
MYSQL_USER=$2
MYSQL_PASSWORD=$3
MYSQL_HOST=$4
[ "${MYSQL_USER}" = ‘‘ ] && MYSQL_USER=zabbix
[ "${MYSQL_PASSWORD}" = ‘‘ ] && MYSQL_PASSWORD=123
[ "${MYSQL_HOST}" = ‘‘ ] && MYSQL_HOST=localhost
[ "${var}" = ‘ ‘ ] && echo ""||${mysql} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -e ‘show status‘|grep -v Variable_name|grep "\b${var}\b"|awk ‘{print $2}‘
修改权限
# chmod 755 /usr/local/zabbix/scripts/mysql.status.sh
测试脚本
# /usr/local/zabbix/scripts/mysql.status.sh Uptime
173778
修改zabbix agent的配置文件
# vim /usr/local/zabbix/etc/zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ --->配置文件key的路径
UnsafeUserParameters=1 ---》允许特殊字符
增加mysql key的配置文件
# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/mysql.status.conf
UserParameter=mysql.status[*],/usr/local/zabbix/scripts/mysql.status.sh $1
UserParameter=mysql.ping,/usr/bin/mysqladmin -uzabbix -p123 ping|grep alive|wc -l
UserParameter=mysql.version,mysql -V|cut -f6 -d" "|sed ‘s/,//‘
然后测试
# /usr/local/zabbix/sbin/zabbix_agentd -t mysql.status[Uptime]
mysql.status[Uptime] [t|174213]
重启agent服务
service zabbix_agentd restart
服务器端测试
# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.237 -k mysql.status[Uptime]
171895
OK,在zabbix添加mysql模板或者等待约1分钟的更新周期查看即可
标签:
原文地址:http://www.cnblogs.com/liqing1009/p/4230620.html