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

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

时间:2016-05-28 19:10:43      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

 

 

[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
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)

技术分享

[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  ]

 

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

标签:

原文地址:http://www.cnblogs.com/bass6/p/5538054.html

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