zabbix监控mysql的性能

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

环境:mysql

zabbix sever: 192.168.234.131linux

mysql :192.168.234.130sql


mysql 客户端操做:ide


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

  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.sh3d


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

三、添加自定义 key 配置文件
rest

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服务xml

/etc/init.d/zabbix_agentd restarthtm

5 最后能够在服务端验证

zabbix_get -s 192.168.234.130 -k mysql.ping

若是返回1便是正常

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

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

wKiom1dFNbKzT5a9AAFazRrIKOI814.png

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

wKioL1dFNsqjLuH_AAJwBtlK810504.png

相关文章
相关标签/搜索