redis-sentinel告警脚本

redis-sentinel告警脚本

   张吉吉     2020年1月6日 01:17     3459    

1、介绍

redis sentinel本身提供了一个比较简单的监控告警方式,就是当发生告警的时候,我们可以自己通过编写一个脚本,将sentinel的告警信息发送到监控人员邮箱或者短信或者其他通信方式的接收器里边。

 

2、配置文件参数

sentinel notification-script <master-name> <script-path>

sentinel notification-script mymaster /usr/local/redis/scripts/warn.sh

配置redis sentinel告警脚本非常的简单,只需要注意配置的脚本的路径即可。

 

3、参数解析

# NOTIFICATION SCRIPT

# Call the specified notification script for any sentinel event that is

# generated in the WARNING level (for instance -sdown, -odown, and so forth).

# This script should notify the system administrator via email, SMS, or any

# other messaging system, that there is something wrong with the monitored

# Redis systems.

# The script is called with just two arguments: the first is the event type

# and the second the event description.

# The script must exist and be executable in order for sentinel to start if

# this option is provided.

 

为警告级别中生成的任何标记事件(例如-sdown、-odown等)调用指定的通知脚本。此脚本应该通过电子邮件、SMS或任何其他消息传递系统通知系统管理员,被监视的Redis系统出现了问题。

调用脚本时只有两个参数:

第一个是事件类型 $1

第二个是事件描述 $2

该脚本必须存在并可执行,以便哨兵启动。

 

4、个人理解

sentinel在监控过程中,如果发现redis出现warning或者以上级别的日志,就将其产生的日志内容发送给监控者的邮箱等。

上边的参数解析中也说明了,在执行脚本的过程中会将两个参数传递到脚本里边。所以只需要将参数的内容通过邮件发送给监控者的邮箱即可。

现在就有了自动触发机制。

 

5、脚本编写

 

(1)测试脚本

其实脚本的编写很简单,只需要将传递进来的参数发送出去即可。我在这里先做了一个实验就是在执行脚本的时候,将内容输出到了文件里边。

脚本内容

#!/bin/bash

echo $1 >> /root/redis-warn.log

echo $2 >> /root/redis-warn.log

在出现问题的时候就会将内容输出到了redis-warn.log日志中。

1.png

 

(2)发送邮件给监控人员

#!/bin/bash

echo $1 $2 >> /root/redis-warn.log

mail –s “redis sentinel warn” nowzhangjunzhe@163.com < /root/redis-warn.log

上边脚本的意思就是将监控类型和事件描述写到/root/redis-warn.log文件中

然后使用mail命令将redis-warn.log中的内容发送给nowzhangjunzhe@163.com这个邮箱

2.png


文章评论

0

其他文章