gpt4 book ai didi

alert - 让监视器先发出警报,然后再重新启动

转载 作者:行者123 更新时间:2023-12-03 12:54:37 25 4
gpt4 key购买 nike

我想在monit中处理一种链式 Action 。

  • 检查进程并立即发出警报。
  • 循环数后重新启动过程。

  • 我的尝试(到目前为止):
    check process myprocess with pidfile /run/my.pid
    start program = "/path/to/binary start" with timeout 60 seconds
    stop program = "/path/to/binary stop" with timeout 60 seconds
    if not exist for 3 cycles then restart
    if not exist then alert
    if 3 restarts within 3 cycles then timeout

    在 PID 失败时不发出警报并保持“运行”状态,但在 3 个周期后重新启动。
    check process myprocess with pidfile /run/my.pid
    start program = "/path/to/binary start" with timeout 60 seconds
    stop program = "/path/to/binary stop" with timeout 60 seconds
    if not exist for 3 cycles then restart
    if children < 1 for 1 cycles then alert
    if 3 restarts within 3 cycles then timeout

    没有 child < 1 的警报,但在 5 岁后重新开始。

    监控日志
    [CEST Aug  1 15:09:30] error    : 'myprocess' process is not running

    监控摘要
    Process 'myprocess'            Running

    这里是 monit -v 部分:
    Existence      = if does not exist 3 times within 3 cycle(s) then restart else 
    if succeeded 1 times within 1 cycle(s) then alert
    Pid = if changed 1 times within 1 cycle(s) then alert
    Ppid = if changed 1 times within 1 cycle(s) then alert
    Children = if less than 1 1 times within 1 cycle(s) then alert else if
    succeeded 1 times within 1 cycle(s) then alert
    Timeout = If restarted 3 times within 3 cycle(s) then unmonitor

    所以问题是:是否可以在 1 个周期内发送警报并将状态更改为“未运行”并在 3 个周期后重新启动?

    最佳答案

    编辑(重要) :有关 Monit 的较新(截至 2019 年 2 月)版本,请参阅下面的评论,其中此行为已得到改进。

    这一行:

    if does not exist for 3 cycles then restart

    意思如下:

    在您检查 3 次服务不存在之前不要执行任何操作,然后重新启动它。这种行为在 monit 的文档中被描述为容错:

    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 ...



    因此,Monit 不会改变服务的状态,直到它在接下来的 X 个周期内失败。为了确认此声明,只需删除此服务的容错并仅使用:
    if does not exist then alert

    手动停止服务并确认命令
    monit status

    停止后立即显示“不存在”状态。

    所以,回到你的问题:
  • 是的,可以在 1 个周期内发送警报(每封电子邮件)。为了
    也就是说,您需要为该服务定义“如果不存在则警报”选项并正确设置电子邮件警报。假设你会
    喜欢使用外部电子邮件服务器,您至少需要定义两个
    行(使用 gmail 的配置示例):

  • SMTP 服务器配置
    set mailserver smtp.gmail.com PORT 587 USERNAME "xxxxxxx@xxxxx.xxx" PASSWORD "xxxxx" using TLSV1 with timeout 30 seconds

    (请注意,在 gmail 中,您必须激活“不安全”应用程序的访问权限才能允许 monit 使用 stmp 服务)



    电子邮件收件人
    set alert xxxxxxx@xxxxx.xxx

    两者都在文件/etc/monit/monitrc 中。有关这两行的更多信息,请参阅官方文档。
  • 就文档而言,如果定义了容错(在 X 个周期后执行操作),则不可能立即更新服务的状态。但是您仍然可以定义要立即发送的警报并在所需的周期内重新启动服务。

  • 引用:

    Monit 的文档: https://mmonit.com/monit/documentation/monit.html

    希望能帮助到你!

    问候

    关于alert - 让监视器先发出警报,然后再重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25081180/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com