zabbix监控mysql以及其他常见

zabbix监控mysql以及其他常见,监控mysql,也可是使用percona提供的详细的模板,里面的监控项目非常的详细

<template>Template Percona MySQL Server</template>

1 监控mysql状态

[root@mysqlhq ~]# 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 脚本

[root@mysqlhq ~]# 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
[mongodb@hongquan1 conf]$ /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k "net.tcp.listen[3306]"
1
[mongodb@hongquan1 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)

猜你喜欢

转载自www.cnblogs.com/yhq1314/p/9921524.html