史上最全最正確的zabbix監控mysql配置方法

來源:互聯網
上載者:User

標籤:zabbix監控   mysql監控   zabbix mysql   

1、組態--主機--建立主機

2、在其他群組中選擇linux server或者建立群組

3、主機名稱為mysql

4、模板中選擇點擊添加,選擇Template App MySQL,點擊存檔

5、添加mysql監控指令碼:

cd /usr/local/zabbix/share/zabbix/alertscripts

vi check_mysql.sh

#!/bin/bash

# 使用者名稱

MYSQL_USER=‘zabbix‘

# 密碼

MYSQL_PWD=‘123456‘

# 主機地址/IP

MYSQL_HOST=‘127.0.0.1‘

# 連接埠

MYSQL_PORT=‘3306‘

# 資料連線

MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -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|Com_begin)"

        ;;

esac

6、修改zabbix代理參數

vi /usr/local/zabbix/etc/zabbix_agentd.conf

# 擷取mysql版本

UserParameter=mysql.version,mysql -V

# 擷取mysql效能指標,這個是上面定義好的指令碼

UserParameter=mysql.status[*],/usr/local/zabbix-2.4.4/scripts/chk_mysql.sh $1

# 擷取mysql運行狀態

UserParameter=mysql.ping,mysqladmin -uzabbix -p123456 -P3306 -h127.0.0.1  ping | grep -c alive

7、重啟zabbix服務

service zabbix_agentd restart


本文出自 “13015170” 部落格,請務必保留此出處http://13025170.blog.51cto.com/13015170/1962649

史上最全最正確的zabbix監控mysql配置方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.