• zabbix4.0监控Mysql数据库


    #wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.11-1.el7.x86_64.rpm

    #rpm -ivh zabbix-agent-3.4.11-1.el7.x86_64.rpm

    [root@lamp02-salve ~]# egrep -v "#|^$" /etc/zabbix/zabbix_agentd.conf
    PidFile=/var/run/zabbix/zabbix_agentd.pid
    LogFile=/var/log/zabbix/zabbix_agentd.log
    LogFileSize=0
    Server=192.168.2.159
    ServerActive=127.0.0.1
    Hostname=Zabbix server
    Include=/etc/zabbix/zabbix_agentd.d/*.conf

    agent端检查mysql脚本

     #vim /etc/zabbix/zabbix_agentd.d/check_mysql 

    #!/bin/bash
    # 主机地址/IP
    MYSQL_HOST='192.168.2.158'
    # 端口
    MYSQL_PORT='3306'
    # 数据连接
    MYSQL_CONN="/usr/local/mysql/bin/mysqladmin  -h${MYSQL_HOST} -P${MYSQL_PORT}"
    
    # 参数是否正确
    if [ $# -ne "1" ];then 
        echo "arg error!" 
    fi 
    
    # 获取数据
    case $1 in 
        Uptime) 
            result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` 
            echo $result 
            ;; 
        Com_update) 
            result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` 
            echo $result 
            ;; 
        Slow_queries) 
            result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` 
            echo $result 
            ;; 
        Com_select) 
            result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3` 
            echo $result 
                    ;; 
        Com_rollback) 
            result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3` 
                    echo $result 
                    ;; 
        Questions) 
            result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` 
                    echo $result 
                    ;; 
        Com_insert) 
            result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3` 
                    echo $result 
                    ;; 
        Com_delete) 
            result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` 
                    echo $result 
                    ;; 
        Com_commit) 
            result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3` 
                    echo $result 
                    ;; 
        Bytes_sent) 
            result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` 
                    echo $result 
                    ;; 
        Bytes_received) 
            result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` 
                    echo $result 
                    ;; 
        Com_begin) 
            result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3` 
                    echo $result 
                    ;; 
    
            *) 
            echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|C
    om_begin)" 
            ;; 
    esac

    通过mysqladmin获取mysql运行状态参数,需要登陆验证密码,这里可以将密码写在/etc/my.conf配置文件中如

    [client]
    host=localhost
    user= 'root'

    password='123.com'

    [root@lamp02-salve zabbix_agentd.d]# chmod o+x /etc/zabbix/zabbix_agentd.d/check_mysql -R

    [root@lamp02-salve zabbix_agentd.d]# chown zabbix.zabbix /etc/zabbix/zabbix_agentd.d/check_mysql

    [root@lamp02-salve ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf    #这里定义一个userparameneter子文件,将监控项key值以及脚本添加进去

    UserParamenter=mysql.status[*],/etc/zabbix/zabbix_agentd.d/check_mysql $1
    UserParamenter=mysql.ping,HOME=/usr/bin/mysqladmin ping 2>/dev/null | grep -c alive
    UserParamenter=mysql.version,/usr/bin/mysql -V

     zabbix web端引入模板

    zabbix自带了mysql监控模板,因此只需要链接即可

    上图便是我们mysql监控项,可以刚发现都对应着键值,都获取agent数据,说明监控成功

  • 相关阅读:
    C++使用静态类成员时出现的一个问题
    C++中的const_cast
    【位运算与嵌入式编程】
    电压取反电路
    bzoj4769
    初赛
    noip2011day2
    uva1252
    codeforces 703d
    poj[1734]
  • 原文地址:https://www.cnblogs.com/bixiaoyu/p/9984008.html
Copyright © 2020-2023  润新知