• zabbix监控mysql


    zabbix自带MySQL的监控模板(Template App MySQL),但不能直接使用,需要在客户端上进行一些设置。

    1、在客户端编写mysql监控脚本

    #!/bin/bash 
    
    MYSQL_SOCK="/var/lib/mysql/mysql.sock"  
    ARGS=1 
    if [ $# -ne "$ARGS" ];then 
        echo "Please input one arguement:" 
    fi 
    case $1 in 
        Uptime) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK status 2>/dev/null|awk -F'[: ]+' '{print $2}'` 
            echo $result 
            ;; 
        Com_update) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Com_update>/{print $3}'` 
            echo $result 
            ;; 
        Slow_queries) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK status 2>/dev/null|awk -F'[: ]+' '{print $9}'` 
            echo $result 
            ;; 
        Com_select) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Com_select>/{print $3}'` 
            echo $result 
            ;; 
        Com_rollback) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Com_rollback>/{print $3}'` 
            echo $result 
            ;; 
        Questions) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK status 2>/dev/null|awk -F'[: ]+' '{print $6}'` 
            echo $result 
            ;; 
        Com_insert) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Com_insert>/{print $3}'` 
            echo $result 
            ;; 
        Com_delete) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Com_delete>/{print $3}'` 
            echo $result 
            ;; 
        Com_commit) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Com_commit>/{print $3}'` 
            echo $result 
            ;; 
        Bytes_sent) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Bytes_sent>/{print $3}'` 
            echo $result 
            ;; 
        Bytes_received) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Bytes_received>/{print $3}'` 
            echo $result 
            ;; 
        Com_begin) 
            result=`/usr/bin/mysqladmin -uzabbix -ppassword -S $MYSQL_SOCK extended-status 2>/dev/null|awk -F'[ |]+' '/Com_begin>/{print $3}'` 
            echo $result 
            ;; 
        *) 
            echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions)" 
            ;; 
    esac

    2、在mysql服务器上面创建一个用于zabbix监控的用户(无权限)

    GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY 'password';

    3、修改客户端zabbix设置

    编辑zabbix_agentd.conf配置文件,添加如下内容:

    UserParameter=mysql.version,mysql -V
    UserParameter=mysql.ping,mysqladmin -uzabbix -plkpower -S /var/lib/mysql/mysql.sock ping 2>/dev/null| grep -c alive
    UserParameter=mysql.status[*],/data/zabbix/externalscripts/zabbix_mysql_status.sh $1

    然后重启zabbix_agentd服务。

    4、服务端测试是否可以正常取值

    5、在zabbix的监控上添加MySQL的模板(Template App MySQL)

    监控效果图如下:

  • 相关阅读:
    二级菜单jquery
    js二级导航
    append appendChild appendTo区别
    cssText在 IE6/7/8和chrome/Firefox/IE9+的不同
    cssText
    css slice和splice
    js字符串函数之substring() substr()
    js字符串函数之split()join()
    Python面向对象之:三大特性:继承,封装,多态以及类的约束
    Python3 面向对象之:多继承
  • 原文地址:https://www.cnblogs.com/Eivll0m/p/5477118.html
Copyright © 2020-2023  润新知