Zabbix Script 报警监控Mysql Slave服务器

监控Mysql Slave 数据库状态
#############################################################################
修改zabbix_server.conf,如下:
### Option: AlertScriptsPath
# Full path to location of custom alert scripts.
# Default depends on compilation options.
#
# Mandatory: no
# Default:报警目录
[color=green]AlertScriptsPath=/zabbix/server/alertscripts[/color]

在mysql slave上添加用户:
FLUSH PRIVILEGES;
CREATE USER 'zabbix'@'%' IDENTIFIED BY 'zabbix';
GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;

在/zabbix/server/alertscripts问题件夹下添加脚本
linux mail 命令:[url]http://www.cnblogs.com/JemBai/archive/2012/01/24/2329136.html[/url]
vim mysqlSlaveStatus.sh
#!/bin/bash
#define mysql variable
mysql_user="zabbix"
mysql_pass="zabbix"
ip="192.168.126.133"
#mysql_status=`netstat -nl | awk 'NR>2{if ($4 ~ /.*:3306/) {print "Yes";exit 0}}'`
#echo "mysql status:"$mysql_status;
slave_status=`mysql -h${ip} -u${mysql_user} -p${mysql_pass} -e"show slave status\G" | grep "Slave_IO_Running\|Slave_SQL_Running:" | awk '{if ($2 != "Yes") {print "No";exit 1}}'`
#echo "salve status:"$slave_status
if [ "$slave_status" == "No" ];then
#echo "slave is not working!"
echo "the slave($ip) is not working " | mail -s "problem:slave" test@qq.com
fi
[color=blue]如果想用短信可以在shell,使用curl call SMS的HTTP地址即可。[/color]

配置系统Media Type:

[img]http://dl2.iteye.com/upload/attachment/0119/2736/92e09453-b325-3bb1-8e5b-47e84d413fff.png[/img]
[color=red]注意脚本文件名带后缀.sh[/color]

配置用户:

[img]http://dl2.iteye.com/upload/attachment/0119/2738/8b2c567a-0c48-3a19-a944-ad8f6a28f50d.png[/img]

创建触发器:
我们以可连通最为触发器,因为检查mysql slave的状态是以可联通作为前提条件

[img]http://dl2.iteye.com/upload/attachment/0119/2740/94d83cba-79df-30be-9b97-e404a48eb657.png[/img]

创建action:

[img]http://dl2.iteye.com/upload/attachment/0119/2742/5dab97e7-4754-3436-9a29-7c3dc76a5135.png[/img]

查看事件状态:

[img]http://dl2.iteye.com/upload/attachment/0119/2744/c7e5284c-9c00-3d97-be98-b0e647a0aaca.png[/img]

查看email:

[img]http://dl2.iteye.com/upload/attachment/0119/2748/f1aa21ba-eb61-36f2-8a8d-4904f3c359a1.png[/img]
[color=red]
问题1:找不到脚本文件/zabbix/server/alertscripts/mysqlSlaveStatus: [2] No such file or directory
查看系统脚本的文件名后缀是否.sh,查看报警目录下是否有对应的报警脚本。[/color]

[color=red]问题2:时间超时timeout while executing a shell script
这个问题是由,zabbix执行shell超时引起的不必过分在意,会重新执行的[/color]。

监控mysql Slave物理机状态
#########################################################################
创建不可达触发器:

[img]http://dl2.iteye.com/upload/attachment/0119/2787/6c561ab5-ab07-37a8-a311-4aefa9ceb6f3.png[/img]

email报警参考:[url]http://donald-draper.iteye.com/blogs/2316456[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值