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

    监控效果图如下:

  • 相关阅读:
    如何使用shell脚本快速排序和去重文件数据
    centos7下搭建git和gitlab版本库
    Jenkins安装部署
    那日了狗的上半年的兼容性问题,下半年来解决。
    RecyclerView notifyDataSetChanged不起作用
    android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法
    java.lang.UnsatisfiedLinkError: Couldn't load hyphenate_av from loader dalvik.system.PathClassLoader
    android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
    apache https配置
    docker进入容器的方式
  • 原文地址:https://www.cnblogs.com/Eivll0m/p/5477118.html
Copyright © 2020-2023  润新知