Zabbix监控Mysql数据库性能--脚本方式
2014-10-31 15:45
936 查看
本文通过Zabbix Graphs实时查看的SQL语句操作情况和mysql发送接收的字节数,Zabbix还可以监控mysql slow queries,mysql version,uptime,alive等。
在之前的博文里面写过如何通过Zabbix监控mysql主从同步是否OK,mysql从库是否有延时(Seconds_Behind_Master)主库,当mysql主从有异常时通过Email或者SMS通知DBA和系统人员。除此之外,Zabbix还可以监控mysql slow queries,mysql version,uptime,alive等。下面通过Zabbix Graphs实时查看的SQL语句操作情况和mysql发送接收的字节数。1.Zabbix官方提供的监控mysql的模板Template App MySQL,可以看到相关的Items和key。
2.把该模板Template App MySQL Link到相关的主机上面,发现Item的Status是不可用的,因为key的值是通过Mysql用户查看"show global status"信息或者用mysqladmin命令查看status或extended-status的信息而取的值。
6.在zabbix前端可以实时查看SQL语句每秒钟的操作次数。
7.在zabbix前端可以实时查看mysql发送接收的字节数。其中bytes received表示从所有客户端接收到的字节数,bytes sent表示发送给所有客户端的字节数。
总结把该脚本放到要监控的服务器上面(Modify mysql user and password),修改UserParameter的参数并重启agentd,Link官方提供的Template App MySQL模板即可。我这里是测试环境用root账号,线上服务器安全期间可以给mysql用户授权readonly权限。根据实际的需求,除了监控上述监控项之外,还可以监控mysql processlist,Innodb等。
原文:http://os.51cto.com/art/201404/435139.htm
在之前的博文里面写过如何通过Zabbix监控mysql主从同步是否OK,mysql从库是否有延时(Seconds_Behind_Master)主库,当mysql主从有异常时通过Email或者SMS通知DBA和系统人员。除此之外,Zabbix还可以监控mysql slow queries,mysql version,uptime,alive等。下面通过Zabbix Graphs实时查看的SQL语句操作情况和mysql发送接收的字节数。1.Zabbix官方提供的监控mysql的模板Template App MySQL,可以看到相关的Items和key。
2.把该模板Template App MySQL Link到相关的主机上面,发现Item的Status是不可用的,因为key的值是通过Mysql用户查看"show global status"信息或者用mysqladmin命令查看status或extended-status的信息而取的值。
mysql> show global status; mysql> show status;3.结合官方提供的key编写Shell脚本,从数据库中取出Items的key的值。
[root@monitor scripts]# cat checkmysqlperformance.sh #!/bin/sh #Create by Lance 2014.10.31 MYSQL_SOCK="/var/lib/mysql/mysql.sock" HOME=/usr/local/zabbix/mysql ARGS=1 if [ $# -ne "$ARGS" ];then echo "Please input one arguement:" fi case $1 in Ping) result=`mysqladmin ping | grep -c alive ` echo $result ;; Version) result=`mysql -V | cut -d" " -f6 |awk -F "," '{print "V" $1}'` echo $result ;; Uptime) result=`mysqladmin -S $MYSQL_SOCK status | cut -d" " -f2 ` echo $result ;; Com_update) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_update | cut -d "|" -f3` echo $result ;; Com_begin) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_begin | cut -d "|" -f3` echo $result ;; Bytes_received) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Bytes_received | cut -d "|" -f3` echo $result ;; Bytes_sent) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Bytes_sent | cut -d "|" -f3` echo $result ;; Com_commit) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_commit | cut -d "|" -f3` echo $result ;; Com_delete) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_delete | cut -d "|" -f3` echo $result ;; Com_insert) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_insert | cut -d "|" -f3` echo $result ;; Questions) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Questions | cut -d "|" -f3` echo $result ;; Com_rollback) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_rollback | cut -d "|" -f3` echo $result ;; Com_select) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_select | cut -d "|" -f3` result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Com_select | cut -d "|" -f3` echo $result ;; Slow_queries) result=`mysqladmin -S $MYSQL_SOCK extended-status | grep -w Slow_queries | cut -d "|" -f3` echo $result ;; esac4.在Zabbix_agentd.conf里面添加UserParameter,格式如下,对于Zabbix来说,脚本其实就是一个插件。
UserParameter=mysql.version,mysql -V UserParameter=mysql.ping,mysqladmin -uroot -p123456 -S /data/mysql/3306/mysql.sock ping | grep -c alive UserParameter=mysql.status[*],/etc/zabbix/scripts/checkmysqlperformance.sh $1 $25.重启agentd服务器,然后在zabbix server用zabbix_get就可以取到key的值。
6.在zabbix前端可以实时查看SQL语句每秒钟的操作次数。
7.在zabbix前端可以实时查看mysql发送接收的字节数。其中bytes received表示从所有客户端接收到的字节数,bytes sent表示发送给所有客户端的字节数。
总结把该脚本放到要监控的服务器上面(Modify mysql user and password),修改UserParameter的参数并重启agentd,Link官方提供的Template App MySQL模板即可。我这里是测试环境用root账号,线上服务器安全期间可以给mysql用户授权readonly权限。根据实际的需求,除了监控上述监控项之外,还可以监控mysql processlist,Innodb等。
原文:http://os.51cto.com/art/201404/435139.htm
相关文章推荐
- Zabbix监控Mysql数据库性能
- zabbix系列(二)zabbix3.0.4添加对mysql数据库性能的监控
- zabbix统一脚本监控方式
- Zabbix监控nginx性能的另外一种方式
- zabbix监控dell服务器脚本及方式key值
- sentinel redis 集群部署+zabbix监控配置+性能测试+多实例自动配置脚本
- Zabbix监控Mysql数据库性能
- zabbix监控mysql数据库性能
- Zabbix监控Mysql数据库性能
- zabbix监控mysql数据库(推荐这种方式:zabbix通过mpm监控mysql的环境搭建)
- Zabbix监控nginx性能的另外一种方式
- 用Semisynchronous Replication半同步,mk-table-checksum数据同步一致性检查,监控主从同步运行状态的脚本等方式加强SQL性能和数据审核
- Zabbix监控Mysql数据库性能
- zabbix系列(二)zabbix3.0.4添加对mysql数据库性能的监控
- zabbix监控mysql数据库性能实现
- zabbix监控mysql数据库性能实现
- zabbix监控mysql数据库性能实现
- 通过loadrunner 11常规通用的C语言API类型的Vuser 方式,测试验证MySQL数据库插入、查询、修改、删除数据性能脚本实例
- zabbix trap 监控windows 服务器raid中个磁盘状态脚本
- DBA常用脚本-性能监控