AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 989804
Accepted
Heino Rötten
Heino Rötten
Asked: 2019-10-30 08:41:21 +0800 CST2019-10-30 08:41:21 +0800 CST 2019-10-30 08:41:21 +0800 CST

为什么在检查程序返回退出代码0时监控日志错误和状态失败

  • 772

问题 1

我想用 monit 版本 5.25.1 监控一个无头运行的 LibreOffice-Process。

这是我对这种方法的监控配置:

cat /etc/monit/conf.d/libreoffice


check program lo-check-8101 with path "/bin/bash /opt/libreoffice/chkloproc.sh TestLOPort8101 8101"
        with timeout 10 seconds
        if status != 0 then exec "/bin/bash /opt/libreoffice/loproc_is_down.sh"
        if status = 0 then exec "/bin/bash /opt/libreoffice/loproc_is_up.sh"

此 LibreOffice 实例正在侦听端口 8101。

如果一切正常,检查脚本将返回 0,如果该 LibreOffice 实例出现错误,则返回 101。我正在通过发送 HTML、请求 TEXT 并检查响应来测试这个正在运行的 LibreOffice 进程的文本转换。

动作脚本 (loproc_is_down.sh / loproc_is_up.sh) 正在添加/删除一个 iptables 规则,以向正在运行的 haproxy 发出状态,该 haproxy 正在端口检查 LibreOffice 实例 / 进程......如果这听起来有点复杂,对不起,但这不是我想在这里谈论的问题。

问题是,我不明白为什么 monit 会记录以下条目:

重启后监控日志

[CET Oct 29 16:58:18] info     : Starting Monit 5.25.1 daemon with http interface at [localhost]:2812
[CET Oct 29 16:58:18] info     : Monit start delay set to 10s
[CET Oct 29 16:58:28] info     : 'host1' Monit 5.25.1 started
[CET Oct 29 16:58:58] error    : 'lo-check-8101' status failed (0) -- no output
[CET Oct 29 16:58:58] info     : 'lo-check-8101' exec: '/bin/bash /opt/libreoffice/loproc_is_up.sh'
[CET Oct 29 16:59:28] error    : 'lo-check-8101' status failed (0) -- no output

...以及“监控状态”中的以下状态屏幕:

monit status
Monit 5.25.1 uptime: 0m

Program 'lo-check-8101'
  status                       Status failed
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  last exit value              0
  last output                  -
  data collected               Tue, 29 Oct 2019 16:58:58

System 'host1'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  load average                 [0.03] [0.02] [0.01]
  cpu                          0.6%us 0.6%sy 0.0%wa
  memory usage                 543.9 MB [7.8%]
  swap usage                   0 B [0.0%]
  uptime                       20d 1h 11m
  boot time                    Wed, 09 Oct 2019 16:47:51
  data collected               Tue, 29 Oct 2019 16:58:58

在我看来,检查脚本返回退出值 0 但状态被报告/解释为“状态失败”。

我不明白,为什么 monit 在其日志文件中报告“错误:... status failed (0)”。

除了解释给定检查脚本程序的最后一个退出代码之外,状态还意味着什么?


问题 2

还有另一个来自monit的反应,我无法理解,也许有人可以向我解释一下?

当我试图通过停止它来伪造一个损坏的 LibreOffice 进程时,monit 确实在一个周期后识别出这一点,并且正在启动想要/配置的操作脚本“loproc_is_down.sh”并将最后一个退出代码正确报告为 101,但使用日志-线

“信息:状态成功(101)”

第一个循环,然后再用

“错误:状态失败(101)”

伪造失败的监控日志

[CET Oct 29 17:14:28] info     : 'lo-check-8101' status succeeded (101) -- Error: Existing listener not found. Unable start listener by parameters. Aborting.
[CET Oct 29 17:14:28] error    : 'lo-check-8101' status failed (101) -- Error: Existing listener not found. Unable start listener by parameters. Aborting.
[CET Oct 29 17:14:28] info     : 'lo-check-8101' exec: '/bin/bash /opt/libreoffice/loproc_is_down.sh'
[CET Oct 29 17:14:58] error    : 'lo-check-8101' status failed (101) -- Error: Existing listener not found. Unable start listener by parameters. Aborting.
[CET Oct 29 17:15:28] error    : 'lo-check-8101' status failed (101) -- Error: Existing listener not found. Unable start listener by parameters. Aborting.

相反的是再次启动 LibreOffice 进程时:

服务再次运行时监控日志

[CET Oct 29 17:15:58] error    : 'lo-check-8101' status failed (0) -- no output
[CET Oct 29 17:15:58] info     : 'lo-check-8101' exec: '/bin/bash /opt/libreoffice/loproc_is_up.sh'
[CET Oct 29 17:15:58] info     : 'lo-check-8101' status succeeded (0) -- no output
[CET Oct 29 17:16:28] error    : 'lo-check-8101' status failed (0) -- no output
[CET Oct 29 17:16:58] error    : 'lo-check-8101' status failed (0) -- no output

看起来monit运行该检查脚本,它返回退出代码0并启动动作脚本“loproc_is_up.sh”并使用“状态成功(0)”报告它

...但在接下来的周期中再次记录“错误:状态失败(0)”。

我不理解monit概念/文档中“状态”的含义......有人可以向我解释吗?

感谢您阅读这篇长文,希望能帮助我回答。

monit
  • 2 2 个回答
  • 1450 Views

2 个回答

  • Voted
  1. Best Answer
    boppy
    2019-11-01T03:19:03+08:002019-11-01T03:19:03+08:00

    Monit 用于捕获受监控实体的问题。

    所以 - 逐行 - 你的配置告诉 Monit:

    check program lo-check-8101 with path "/bin/bash /opt/libreoffice/chkloproc.sh TestLOPort8101 8101" with timeout 10 seconds
    

    执行二进制。存储退出代码和一些附加信息。

            if status != 0 then exec "/bin/bash /opt/libreoffice/loproc_is_down.sh"
    

    如果状态不为 0,则会出现问题。现在执行一个二进制文件。

            if status = 0 then exec "/bin/bash /opt/libreoffice/loproc_is_up.sh"
    

    如果状态为 0,则会出现问题。现在执行一个二进制文件。- 我什至不知道这个电话的结果应该是什么。这里一切都好,那为什么要执行一些事情呢?


    可以这么说:有了这个配置,就没有“成功”(=一切都很好)的情况。

    要优化它,你应该只发现 Monit 的问题:

    check program lo-check-8101 with path "/opt/libreoffice/chkloproc.sh TestLOPort8101 8101"
        with timeout 10 seconds
        if status != 0 then exec "/opt/libreoffice/loproc_is_down.sh"
        if 2 restarts within 3 cycles then unmonitor
    
    

    这意味着如果状态为 0,Monit 不会执行任何操作。

    配置上还有一些话:

    1. 如果我理解正确(见这个问题),无头服务器将创建一个 PID 文件。所以你也可以检查一下check process,也许还有一些send/expect魔术来验证服务是否正在运行。
    2. 如果您将.sh文件设置为可执行文件(+x; ie. chmod +x /opt/libreoffice/*.sh)并且在这些文件中有正确的shebang,则可以在执行时省略/bin/bash以提高可读性。

    我对此的配置(不知道使用什么协议:8101,假设 http)将更像这样:

    check process libre-local with pidfile "/var/run/libreoffice-server.pid"
        start program = "/usr/bin/systemctl start libreoffice-server" # Unit name is an assumption!
        stop program = "/usr/bin/systemctl stop libreoffice-server" # Unit name is an assumption!
    
        if failed
            port 8101
            protocol http
            request "/any_valid_entrypoint"
            for 2 cycles
        then restart
    
        # if loadavg (5min) per core > 1 for 5 cycles then restart
        if loadavg (5min) > 4 for 5 cycles then restart
        if totalmem > 2 GB for 5 cycles then restart
        if 3 restarts within 5 cycles then unmonitor
    

    loadavg使用per core需要最新的 Monit 版本。所以它可能在你的发行版中不可用,所以我注释掉了这一行;)


    OP回复后编辑(我希望你得到通知):

    (我们不能评论 < 50 Rep 真的很痛苦......)

    如果我做对了,你必须转换一些东西来获取应用程序的状态,如果转换失败,应用程序应该重新启动。翻译成监视器:

    check program lo-check-8101 with path "CONVERT_HERE"
        with timeout 10 seconds
        if status != 0 then exec "/usr/bin/systemctl restart libreoffice-server"
        if 2 restarts within 3 cycles then unmonitor
    

    ...CONVERT_HERE如果转换顺利,可执行文件以 0 退出,如果转换失败,则以 <>0 退出。我仍然觉得我在这里错过了一些东西。;)

    您能否将所有三个可执行文件都放到一个要点或其他东西上?

    • 0
  2. Heino Rötten
    2019-11-01T07:48:33+08:002019-11-01T07:48:33+08:00

    @boppy:谢谢你的回答。

    你是对的,我需要处理“Headless Libre Office”流程。

    LibreOffice 有点讨厌,并且正在接受连接,尽管它已经挂断了......所以如果你能够转换某些东西(这发生在检查脚本中),你只能知道正在运行的 lo 进程的健康状况。

    因此,如果转换不起作用,我不能依赖 PID 或端口检查......并尝试使用我的检查脚本 + monit 来拒绝连接。

    这背后的想法是:

    如果 monit 正在向 iptables 添加规则以拒绝与 lo 进程的连接,则它应该删除那些添加的规则,如果 lo 进程恢复/健康并再次转换。

    也许 monit 是执行此操作的错误工具,或者我只是想复杂......但 monit 看起来比使用 cron 执行这些检查和 iptables 更合适......也许我会尝试 cron。


    我从您的回答中学到了一件重要的事情,即没有成功状态,如果我在 monit 配置中使用“IF STATUS = 0 THEN EXEC ...”行。

    因此,monit 不会将退出值 0 解释为“成功”,因为这个“IF ... EXEC”行。


    并感谢您的 monit-config ... 如果 lo 进程变得疯狂,重新启动它们似乎是个好主意。


    但是monit仍然有问题......我通过将“-v”作为/etc/defaults/monit的选项打开调试来启动monit并查看以下日志行:(monits周期配置为30秒长)

    [CET Oct 31 16:49:00] error    : 'lo-check-8101' status failed (0) -- conversion ok
    [CET Oct 31 16:49:00] debug    : 'lo-check-8101' status succeeded (0) -- conversion ok
    [CET Oct 31 16:49:00] debug    : 'lo-check-8101' program started
    [CET Oct 31 16:49:30] error    : 'lo-check-8101' status failed (0) -- conversion ok
    [CET Oct 31 16:49:30] debug    : 'lo-check-8101' status succeeded (0) -- conversion ok
    [CET Oct 31 16:49:30] debug    : 'lo-check-8101' program started
    

    这是一个监视器错误吗?也许我需要更新版本的 monit。

    • 0

相关问题

  • 同一 Monit 作业的暂存和生产版本

  • 重新启动崩溃进程的简单方法?

  • 使用自定义 gem 路径监视和 backgroundrb

  • 我如何配置 monit 以启动特定用户的进程?

  • 监控连接测试,未捕获 -1 响应

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve