get monit to alert first and restart later

元气小坏坏 提交于 2019-12-03 05:48:07

EDIT (IMPORTANT): See comments below for newer (as per Feb. 2019) versions of Monit, where this behaviour has been improved.


This line:

if does not exist for 3 cycles then restart

Means the following:

Do not perform any action until you have checked 3 times that the service does not exist, then restart it. This behaviour is described in monit's documentation as Failure Tolerance:

FAILURE TOLERANCE

By default the action is executed if it matches and the service set in an error state. However, you can require a test to fail more than once before the error event is triggered and the service state changed to failed. This is useful to avoid getting alerts on spurious errors, which can happen, especially with network tests.

Syntax:

FOR CYCLES ... or:

[TIMES WITHIN] CYCLES ...

Accordingly, Monit wont change the service's status until it fails within the next X cycles. In order to confirm this statement, just remove the fault tolerance for this service and use only:

if does not exist then alert

stop manually the service and confirm that the command

monit status

shows now the status "Does not exist" as soon as you stop it.

So, back to your questions:

  1. Yes, it is possible to send an alert (per Email) within 1 cycle. For that, you need to define the option "if does not exist then alert" for that service and setup Email-Alerts correctly. Assuming you would like to use an external eMail-Server, you need to define at least two lines (Configuration Example with gmail):

SMTP SERVER CONFIGURATION

set mailserver smtp.gmail.com PORT 587 USERNAME "xxxxxxx@xxxxx.xxx" PASSWORD "xxxxx" using TLSV1 with timeout 30 seconds

(Be aware that in gmail you must activate the access for "unsecure" apps in order to allow monit to use the stmp service)

and

EMAIL RECIPIENT

set alert xxxxxxx@xxxxx.xxx

both in the file /etc/monit/monitrc. Refer to the official documentation for more information about these two lines.

  1. As far as the documentation tells, it is not possible to update the status of the service inmediately if a fault tolerance (perform action after X cycles) is defined. But you can still define alerts to be sent inmediately and restart the service within the desired cycles.

References:

Monit's documentation: https://mmonit.com/monit/documentation/monit.html

Hope it helps!

Regards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!