码迷,mamicode.com
首页 > 数据库 > 详细

zabbix监控mysql的性能

时间:2016-05-25 15:19:40      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:mysql 性能 zabbix

参考  http://www.linuxidc.com/Linux/2016-04/130436.htm

环境:

zabbix sever: 192.168.234.131

mysql :192.168.234.130


mysql 客户端操作:


1 添加监控用户,登入到数据里然后:

  GRANT USAGE ON *.* TO ‘zabbix‘@‘localhost‘ IDENTIFIED BY ‘zabbix‘ WITH GRANT OPTION;
 MariaDB [(none)]>  flush privileges;      ##刷新系统授权
 MariaDB [(none)]> grant all on zabbix.* to ‘zabbix‘@‘127.0.0.1‘ identified by ‘zabbix‘ with grant option;


 

2 编写脚本 vi /usr/local/zabbix/scripts/mysql_status.sh


User=‘zabbix‘
Password=‘zabbix‘
Mysql=‘/usr/bin/mysql‘
Mysqladmin=‘/usr/bin/mysqladmin‘
command(){
  $Mysql -u $User -p$Password -e "show global status" | awk ‘$1 ~ /‘"$1"‘$/ {print $2}‘
}
case $1 in
  Com_select)
    command $1 ;;
  Com_insert)
    command $1 ;;
  Com_update)
    command $1 ;;
  Com_delete)
    command $1 ;;
  Com_begin)
    command $1 ;;
  Com_commit)
    command $1 ;;
  Com_rollback)
    command $1 ;;
  Questions)
    command $1 ;;
  Slow_queries)
    command $1 ;;
  Bytes_received)
    command $1 ;;
  Bytes_sent)
    command $1 ;;
  Uptime)
    command $1 ;;
  Version)
    $Mysql -V | awk -F ‘[ ,]‘ ‘{print $6}‘ ;;
  Ping)
    $Mysqladmin -u$User -p$Password ping | wc -l ;;
  *)
    echo "Usage: $0 { Com_select|Com_insert|Com_update|Com_delete|Com_begin|Com_commit|Com_rollback|Questions|Slow_queries|Bytes_received|Bytes_sent|Ping|Uptime|Version }" ;;
esac

3、添加自定义 key 配置文件

vi /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=mysql.status[*],/usr/local/zabbix/scripts/mysql_status.sh $1
UserParameter=mysql.ping,/usr/local/zabbix/scripts/mysql_status.sh Ping
UserParameter=mysql.version,/usr/local/zabbix/scripts/mysql_status.sh Version


4 重启zabbix_agentd服务

/etc/init.d/zabbix_agentd restart

5 最后可以在服务端验证

zabbix_get -s 192.168.234.130 -k mysql.ping

如果返回1即是正常

6 添加zabbix自带的mysql模板,确认出图

 1)在zabbix前端可以实时查看mysql发送接收的字节数。其中bytes received表示从所有客户端接收到的字节数,bytes sent表示发送给所有客户端的字节数。

技术分享

  2)实时查看SQL语句每秒钟的操作次数

技术分享

本文出自 “渐行渐远” 博客,请务必保留此出处http://825536458.blog.51cto.com/4417836/1782982

zabbix监控mysql的性能

标签:mysql 性能 zabbix

原文地址:http://825536458.blog.51cto.com/4417836/1782982

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!