zabbix监控mysql
一、数据库给只读权限
1.1 grant usage on *.* to 'zabbix'@'127.0.0.1' identified by 'zabbix'; flush privileges; 1.2 mysql -uzabbix -pzabbix -h 127.0.0.1 -e "show global status" Com_select从mysql启动以来接收的select语句的数量,它是一直往上增的。 Threads_connected获取的是一种当前的状态 1.3 mysql -uzabbix -pzabbix -h 127.0.0.1 -e "show global status"|grep 'Threads_connected'
二、zabbix监控mysql脚本(check_mysql.sh)
#!/bin/sh while getopts "u:p:P:k:" opt do case $opt in u ) user=$OPTARG;; p ) password=$OPTARG;; P ) port=$OPTARG;; k ) key=$OPTARG;; ? ) echo 'parameter is wrong!' exit 1;; esac done if [ ! "${user}" ] || [ ! "${password}" ] || [ ! "${port}" ];then echo "parameter is null" exit 1 fi mysql -u ${user} -p${password} -h 127.0.0.1 -P${port} -e "show global status"|grep "${key}[[:space:]]"|awk '{print $2}'
三、zabbix自定义监控mysql的agent配置(vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/mysql.conf)
UserParameter=mysql.status[*],sh /usr/local/zabbix/check_mysql.sh -u zabbix -p zabbix -P $1 -k $2 2>/dev/null 配置完需要重启zabbix_agentd(pkill zabbix_agentd; sleep 3; /usr/local/zabbix/sbin/zabbix_agentd)
四、测试下看能否获取到值
zabbix_get -s 172.16.0.3 -k mysql.status[3306,Com_select]
五、网页上添加监控
net.tcp.service.perf[tcp,,3306] mysql.status[3306,Threads_connected] mysql.status[3306,Com_select] mysql.status[3306,Com_update] mysql.status[3306,Com_insert] mysql.status[3306,Com_delete]
六、创建图形进行查看
七、触发器的增加
八、可设置成模板