MySQL健康检查(二)

简单说明:

在《MySQL健康检查(一)》中的实时监控脚本使用了mysqladmin 的ext搂取MySQL当前运行状态,然后抓取了关键字进行报表监控。
实际上该命令和使用mysql -e “show global status” 监控输出的内容是一样的:

mysqladmin -uroot -pvincent ext
mysql -uroot -pvincent -t -e "show global status"

那么进一步对MySQL当前运行状态进行分析监控实验。

实验:

# 约定
mysql -uroot -pvincent -e "show global status"|awk '{print $1}'|grep 'Access'
# Access_denied_errors
# 状态关键字Access_denied_error以下划线作为分割
# 第一级为Access,第二级为denied,第三级为error

# 查看 show global status 第一级状态关键字和对应的数量
mysql -uroot -pvincent -e "show global status"|\
grep -v '^Variable_nam.*Value$'|awk -F'_|\t' '{print $1}'|uniq -c

# 查看 show global status 第二级状态关键字和对应的数量
mysql -uroot -pvincent -e "show global status"|\
grep -v '^Variable_nam.*Value$'|awk -F'_|\t' '{print $1"_"$2}'|uniq -c

# 轮询查看 show global status 第一级状态关键字状态
mysql -uroot -pvincent -e "show global status"|\
grep -v '^Variable_nam.*Value$'|awk -F'_|\t' '{print $1}'|uniq|\
while read key;do mysql -uroot -pvincent -e "show global status like '${key}%'"|column -t;\
sleep 2;clear;done

# 轮询查看 show global status 第二级状态关键字状态
mysql -uroot -pvincent -e "show global status"|\
grep -v '^Variable_nam.*Value$'|awk -F'_|\t' '{print $1"_"$2}'|uniq|\
while read key;do mysql -uroot -pvincent -e "show global status like '${key}%'"|column -t;\
sleep 2;clear;done

# 也可以根据第一级或第二级状态关键字列表,选取需要的关键字进行监控
# 也就是根据所需的关键字,替换和修改《MySQL健康检查(一)》中的实时监控的脚本达到定制监控的目的

[TOC]

猜你喜欢

转载自blog.csdn.net/zwjzqqb/article/details/80876254