1. 程式人生 > >zabbix監控mysql以及其他常見

zabbix監控mysql以及其他常見

zabbix監控mysql以及其他常見,監控mysql,也可是使用percona提供的詳細的模板,裡面的監控專案非常的詳細

<template>Template Percona MySQL Server</template>

1 監控mysql狀態

[[email protected] ~]# cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -v '^#' | grep -v '^$'

UserParameter=mysql.ping,/usr/bin/mysqladmin -uzabbix -pzabbix -h127.0.0.1 -P3306 2>/dev/null ping|grep alive|wc -l
UserParameter=mysql.status[*],/usr/bin/mysql -h 127.0.0.1 -P3306 -uzabbix -p'zabbix' -N -e "show global status where Variable_name='$1'" 2>/dev/null | cut -f2
UserParameter=mysql_variable_status[*],/usr/bin/mysql -h 127.0.0.1 -P3306 -uzabbix -p'zabbix' -N -e "show variables where Variable_name='$1'" 2>/dev/null | cut -f2
UserParameter=mysql.version,/usr/bin/mysql -V
UserParameter=mysql.mysql_process_status,sh /usr/local/zabbix/lib/alertscripts/check_mysql_status_3306.sh

2 指令碼

[[email protected] ~]# cat  /usr/local/zabbix/lib/alertscripts/check_mysql_status_3306.sh

#!/bin/bash
host=127.0.0.1
username=system
password=mysql
port=3306
CHECK_TIME=3
#mysql  is working MYSQL_IS_OK is 1 , mysql down MYSQL_IS_OK is 0
MYSQL_IS_OK=1
function check_mysql_status (){
    /usr/bin/mysql -u$username
-p"$password" -P$port -h$host -e "select user();" >/dev/null 2>&1 if [ $? = 0 ] ;then MYSQL_IS_OK=1 else MYSQL_IS_OK=0 fi return $MYSQL_IS_OK } while [ $CHECK_TIME -ne 0 ] do let "CHECK_TIME -= 1" check_mysql_status if [ $MYSQL_IS_OK = 1 ] ; then CHECK_TIME
=0 echo 1 exit 0 fi if [ $MYSQL_IS_OK -eq 0 ] && [ $CHECK_TIME -eq 0 ] then echo 0 exit 1 fi sleep 3 done

check_slave_status_3306.sh

#監控slave,這裡監控2個執行緒,正常返回值2,返回1或者0都是有錯誤,可以在trigger裡面進行配置

#!/bin/bash
host=127.0.0.1
username=zabbix
password=zabbix
port=3306
#mysql slave is working then return 2,others is error
/usr/bin/mysql -u$username -p"$password" -P$port -h$host  2>/dev/null \
-e "show slave status\G"  |grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'|grep -c Yes

3 監控其他埠,比如mongodb

--使用zabbix自帶key監控程序與埠
1、監控埠
監控埠使用如下key:
key:net.tcp.listen[port]
Checks if this port is in LISTEN state. 0 - it is not, 1 - it is inLISTEN state.
翻譯:監聽埠狀態,返回結果為1,則執行;返回結果為0,則沒有執行。
例如監控443埠,net.tcp.listen[443]
--templates
--application
--items
----name= LISTEN_prot_test_8066
----key=net.tcp.listen[8066]
--triggers
----Expression={LISTEN_prot_test:net.tcp.listen[8066].max(#2)}=0
[[email protected] conf]$ /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k "net.tcp.listen[3306]"
1
[[email protected] conf]$ /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k "net.tcp.listen[28002]"
1

 

4 監控磁碟

# cat /proc/diskstats |grep sda |head -1

UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}' //磁碟讀的次數
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}' //磁碟讀的毫秒數
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}' //磁碟寫的次數
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}' //磁碟寫的毫秒數
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}' //花費在IO操作上的毫秒數
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}' //讀扇區的次數(一個扇區的等於512B)
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}' //寫扇區的次數(一個扇區的等於512B)