zoukankan      html  css  js  c++  java
  • 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  ]
    
  • 相关阅读:
    DIJ最短路
    快速输入/输出
    Codeforces Round #610 (Div. 2).K for the Price of One (Hard Version)
    Codeforces Round #625 (Div. 1, based on Technocup 2020 Final Round).B. Navigation System
    Codeforces Round #612 (Div. 2)C. Garland
    Codeforces Round #621 (Div. 1 + Div. 2).D. Cow and Fields
    73.Python中ORM聚合函数详解:Count
    72.Python中ORM聚合函数详解:Avg,aggregate,annotate
    17. Getting to the essence of things
    55.ORM外键:引用同app下的不同模型,引用不同app下的模型,引用模型自身使用详解
  • 原文地址:https://www.cnblogs.com/bass6/p/5538054.html
Copyright © 2011-2022 走看看