zabbix 监控客户端数据库 zabbix客户端

 

 

[root@zabbix客户端 zabbix]# grep -v "^$" etc/zabbix_agentd.conf|grep -v "^#"
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1,zabbix_server_ip
ServerActive=zabbix_server_ip:10051#注意加端口号
Hostname=113.86.103.100#与zabbix_server端要保持一至,如下图:(A)
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1 #启用自定义key
UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],/usr/local/zabbix/scripts/chk_mysql.sh $1
UserParameter=mysql.ping,mysqladmin -uzabbix -pzabbix -P3306 -h127.0.0.1 ping|grep -c alive

 (A)

mysql> grant select on *.* to "zabbix"@"%" identified by "zabbix";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

 

[root@zabbix客户端 zabbix]# cd scripts/
[root@zabbix客户端 scripts]# ls
chk_mysql.sh
[root@zabbix客户端 scripts]# vi chk_mysql.sh 

 

#!/bin/sh
#set -x
MYSQL_SOCK="/tmp/mysql.sock"
MYSQL_PWD=xxxxx
ARGS=1
MYSQLADMIN=/alidata/server/mysql/bin/mysqladmin#注意命令在脚本里一定要用命令的在绝对路径
if [ $# -ne "$ARGS" ];then
      echo "Please input onearguement:"
fi
case $1 in
     Uptime)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK status|cut -f2 -d":"|cut -f1 -d"T"`
            echo $result
            ;;
        Com_update)
            result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_update"|cut -d"|" -f3`
            echo $result
            ;;
        Slow_queries)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK status |cut -f5 -d":"|cut -f1 -d"O"`
                echo $result
                ;;
    Com_select)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_select"|cut -d"|" -f3`
                echo $result
                ;;
    Com_rollback)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
                echo $result
                ;;
    Questions)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK status|cut -f4 -d":"|cut -f1 -d"S"`
                echo $result
                ;;
    Com_insert)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_insert"|cut -d"|" -f3`
                echo $result
                ;;
    Com_delete)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_delete"|cut -d"|" -f3`
                echo $result
                ;;
    Com_commit)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_commit"|cut -d"|" -f3`
                echo $result
                ;;
    Bytes_sent)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_sent"|cut -d"|" -f3`
                echo $result
                ;;
    Bytes_received)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
                echo $result
                ;;
    Com_begin)
        result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -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

 

[root@zabbix客户端 scripts]# service zabbix_agentd restart
Shutting down zabbix_agentd:                               [  OK  ]
Starting zabbix_agentd:                                    [  OK  ]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值