无法让 monit 运行“exec”操作

无法让 monit 运行“exec”操作

我在 CentOS 6.5 上进行了安装monit。检测到事件并发送警报邮件,但我试图通过该exec功能在事件触发时发生其他事情,但这些都不起作用。

例如,我有一条规则:

if cpu usage (user) > 10% then 
   exec "/bin/echo 'user limit' >> /tmp/monit-status-log" as uid someuser and gid somegroup

该规则在 CPU 负载下适当触发,但未将任何内容写入文件(其保护设置为 rw-rw-rw)。

我猜,执行的日志文件看起来是正确的:

[PST Feb 20 09:31:04] info     : 'linux2.example.com' Monit reloaded
[PST Feb 20 09:31:31] info     : Reinitializing monit daemon
[PST Feb 20 09:31:31] info     : Awakened by the SIGHUP signal
[PST Feb 20 09:31:31] info     : Reinitializing monit - Control file '/etc/monit.conf'
[PST Feb 20 09:31:31] info     : Shutting down monit HTTP server
[PST Feb 20 09:31:32] info     : monit HTTP server stopped
[PST Feb 20 09:31:32] info     : Starting monit HTTP server at [*:2812]
[PST Feb 20 09:31:32] info     : monit HTTP server started
[PST Feb 20 09:31:32] info     : 'linux2.example.com' Monit reloaded
[PST Feb 20 09:32:32] error    : 'linux2.example.com' cpu user usage of 24.4% matches resource limit [cpu user usage>10.0%]
[PST Feb 20 09:32:32] info     : 'linux2.example.com' exec: /bin/echo
[PST Feb 20 09:33:32] info     : 'linux2.example.com' 'linux2.example.com' cpu user usage check succeeded [current cpu user usage=0.0%]

有什么想法或建议吗?

答案1

我认为您应该exec像这样设置命令以使其按预期工作:

if cpu usage (user) > 10% then
  exec "/bin/bash -c '/bin/echo user limit >> /tmp/monit-status-log'" as uid someuser and gid somegroup

相关内容