Zabbix agentd 配置MySQL监控

3 篇文章 0 订阅
3 篇文章 0 订阅

1、手动写一个监控脚本

vim /usr/local/etc/checkmysql.sh

#!/bin/sh
MYSQL_SOCK="/var/lib/mysql/mysql.sock"
ARGS=1
if [ $# -ne "$ARGS" ];then
    echo "Please input onearguement:"
fi
case $1 in
   Uptime)
       result=`mysqladmin -uroot -S $MYSQL_SOCK status|cut -f2 -d":"|cut -f1 -d"T"`
           echo $result
           ;;
   Com_update)
           result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Com_update"|cut -d"|" -f3`
           echo $result
           ;;
   Slow_queries)
       result=`mysqladmin -uroot -S $MYSQL_SOCK status |cut -f5 -d":"|cut -f1 -d"O"`
               echo $result
               ;;
   Com_select)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Com_select"|cut -d"|" -f3`
               echo $result
               ;;
   Com_rollback)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
               echo $result
               ;;
   Questions)
       result=`mysqladmin -uroot -S $MYSQL_SOCK status|cut -f4 -d":"|cut -f1 -d"S"`
               echo $result
               ;;
   Com_insert)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Com_insert"|cut -d"|" -f3`
               echo $result
               ;;
   Com_delete)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Com_delete"|cut -d"|" -f3`
               echo $result
               ;;
   Com_commit)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Com_commit"|cut -d"|" -f3`
               echo $result
               ;;
   Bytes_sent)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Bytes_sent"|cut -d"|" -f3`
               echo $result
               ;;
   Bytes_received)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
               echo $result
               ;;
   Com_begin)
       result=`mysqladmin -uroot -S $MYSQL_SOCK extended-status |grep -w "Com_begin"|cut -d"|" -f3`
               echo $result
               ;;
                      
       *)
       echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions)"
       ;;
esac

2、配置mysql不在命令行输入密码的访问(为了不出现Warning: Using apassword on the command line interface can be insecure.)

vim /var/lib/mysql/my.cnf  (放在/root/.my.cnf或/var/lib/mysql/.my.cnf中都不起作用,放在/etc/my.cnf中可以起作用,但不太好)

特别注意(如果开启selinux的策略是enforcing, 那么要执行 chmod 660 /var/lib/mysql/my.cnf  否则selinux的策略导致无法重启mysql及自启动。selinux的审计日志在/var/log/audit/audit.log中)

[mysqladmin]
user=root
password=xxxx

这样就可以在命令行mysql -uroot  不输入密码情况下就能进行操作

3、配置zabbix_agentd.conf

vim /usr/local/etc/zabbix_agentd.conf

### Option: UserParameter
#       User-defined parameter to monitor. There can be several user-defined parameters.
#       Format: UserParameter=<key>,<shell command>
#       See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
UserParameter=mysql.version,mysql -V
UserParameter=mysql.ping,mysqladmin -uroot -S /var/lib/mysql/mysql.sock ping | grep -c alive
UserParameter=mysql.status[*],/usr/local/etc/checkmysql.sh $1 $2

重启zabbix_agentd

killall zabbix_agentd

service zabbix_agentd start

4、在zabbix frontend中配置mysql,即选择app mysql模板

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值