博客 / 詳情

返回

Zabbix監控mysl數據庫配置

   用mysql自帶的模板,可以監控如下內容:

OPS(增刪改查)、mysql請求流量帶寬,mysql響應流量帶寬,最後會附上相應的監控圖!

一、編寫腳本 check_mysql.sh
vi /usr/local/zabbix/share/check_mysql.sh

!/bin/bash

-------------------------------------------------------------------------------

FileName: check_mysql.sh

Revision: 1.0

Date: 2015/06/09

Author: DengYun

Email: dengyun@ttlsa.com

Website: www.ttlsa.com

Description:

Notes: ~

-------------------------------------------------------------------------------

Copyright: 2015 (c) DengYun

License: GPL

用户名

MYSQL_USER='root'

密碼

MYSQL_PWD='sjt@123'

主機地址/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

二、更改zabbix-agent配置文件
增加自定義key 配置文件最後增加即可
vi /usr/local/zabbix/etc/zabbix_agentd.conf

獲取mysql版本

UserParameter=mysql.version,mysql -V

獲取mysql性能指標,這個是上面定義好的腳本

UserParameter=mysql.status[*],/usr/local/zabbix/share/check_mysql.sh $1

獲取mysql運行狀態

UserParameter=mysql.ping,mysqladmin -uroot -psjt@123 -P3306 -h127.0.0.1 ping | grep -c alive

備註:請注意修改你的數據庫信息,以及zabbix路徑信息 ,這裏沒有必要給root用户

三、重啓zabbix ,mysql

四、zabbix-server中應用模板 結束

温馨提示!應用之後需要等待5分鐘左右 可以抽個煙 後看效果

user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.