zabbix监控mysql脚本(仅供参考)

Posted kkblog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix监控mysql脚本(仅供参考)相关的知识,希望对你有一定的参考价值。

mysql客户端添加

/etc/zabbix/zabbix_agentd.d、userparameter_mysql.conf

UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],/etc/zabbix/scripts/chk_mysql.sh $1
UserParameter=mysql.ping,mysqladmin -uzabbix -p123456 -P3306 -h10.0.0.6  ping | grep -c alive

mysql客户端监控脚本

mkdir /etc/zabbix/scripts/
touch /etc/zabbix/scripts/chk_mysql.sh
chmod u+x /etc/zabbix/scripts/chk_mysql.sh
chown -R zabbix.zabbix /etc/zabbix/scripts/chk_mysql.sh
/etc/zabbix/scripts/chk_mysql.sh

#!/bin/sh
# -------------------------------------------------------------------------------
# Author:      kk
# Email:       [email protected]163.com
MYSQL_PWD=123456
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
    echo "Please input one arguement:"
fi
case $1 in
            echo $result
            ;;
        Com_update)
            echo $result
            ;;
        Slow_queries)
                ;;
    Com_select)
                echo $result
                ;;
    Com_rollback)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_rollbac
k"|cut -d"|" -f3`
                echo $result
                ;;
    Questions)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -p${MYSQL_PWD} -S $MYSQL_SOCK status|cut -f4 -d":"|cut -f1 -d"S"`
                echo $result
                ;;
    Com_insert)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_insert"
|cut -d"|" -f3`
                echo $result
                ;;
    Com_delete)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_delete"
|cut -d"|" -f3`
                echo $result
                ;;
    Com_commit)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_commit"
|cut -d"|" -f3`
                echo $result
                ;;
    Bytes_sent)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_sent"
 |cut -d"|" -f3`
                echo $result
                ;;
    Bytes_received)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_recei
ved" |cut -d"|" -f3`
                echo $result
                ;;
    Com_begin)
        result=`/application/mysql/bin/mysqladmin -u$MYSQL_USER -h$MYSQL_HOST -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
               


mysql压力测试命令

mysqlslap -a -i 10000 -uroot -p123.asd

 

服务端执行获取客户端主机名

/application/zabbix/bin/zabbix_get -s 10.0.0.6 -p 10050 -k "system.hostname"

 

服务端执行获取客户端key值

/application/zabbix/bin/zabbix_get -s 10.0.0.6 -p 10050 -k "system.cpu.load[all,avg15]"

  

服务端执行获取客户端key值

/application/zabbix/bin/zabbix_get -s 10.0.0.6 -p 10050 -k "mysql.status[Uptime]"

  

 

 


以上是关于zabbix监控mysql脚本(仅供参考)的主要内容,如果未能解决你的问题,请参考以下文章

zabbix监控mysql主从状态

zabbix脚本监控mysql

zabbix--监控MySQL性能

zabbix监控Mysql主从状态

zabbix监控mysql性能

使用 zabbix 自动发现监控 MySQL