mysql的基础监控
- 进程存活
- 检测端口
mysql的高级监控说明
mysql提供show global status
可以实现对mysql的高级监控。高级监控包含监控mysql连接数、增删改查数、流量等
开通最小权限用户
grant usage on *.* to 'monitor'@'127.0.0.1' identified by 'monitorpwd';
flush privileges;
监控命令详解
mysql -umonitor -h 127.0.0.1 -pmonitorpwd -e 'show global status'
# Threads_connected:连接数
# Com_select:查询总量
# Com_insert:插入总量
# Com_update:更新总量
# Com_delete:删除总量
# Bytes_received:流入总流量
# Bytes_sent:流出总流量
# Slow_queries:慢查询总量
监控脚本
cat >/tmp/check_mysql.sh <<EOF
key=\$1
port=\$2
mysql -umonitor -pmonitorpwd -h 127.0.0.1 -P\$port -e 'show global status' 2>/dev/null | grep "\$key\s" | awk '{print \$2}'
EOF
脚本测试
sh /tmp/check_mysql.sh Threads_connected
Zabbix自定义key配置
cat >/usr/local/zabbix/etc/zabbix_agentd.conf.d/check_mysql.conf <<EOF
UserParameter=mysql.status[*],sh /tmp/check_mysql.sh \$1 \$2 2>/dev/null
EOF
pkill zabbix_agentd
zabbix_agentd
测试是否能够获取值
zabbix_get -s 127.0.0.1 -k mysql.status[Threads_connected]
使用模板去监控mysql
mysql.status[Threads_connected,3306]
mysql.status[Com_select,3306]
mysql.status[Com_insert,3306]
mysql.status[Com_update,3306]
mysql.status[Com_delete,3306]
mysql.status[Bytes_received,3306]
mysql.status[Bytes_sent,3306]
mysql.status[Slow_queries,3306]