首页
学习
活动
专区
圈层
工具
发布

调试monit
EN

Stack Overflow用户
提问于 2010-07-29 03:08:40
回答 7查看 33.4K关注 0票数 80

我发现调试monit是一件很痛苦的事情。Monit的shell环境基本上没有任何内容(没有路径或其他环境变量)。而且,我找不到日志文件。

问题是,如果monit脚本中的start或stop命令失败,就很难辨别出它出了什么问题。通常,这并不像在shell上运行命令那么简单,因为shell环境与monit shell环境不同。

人们用来调试monit配置的一些技术是什么?

例如,我很乐意有一个monit shell,用来测试我的脚本,或者用一个日志文件来查看哪里出了问题。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2011-01-18 08:29:18

我也遇到过同样的问题。使用monit的详细命令行选项有点帮助,但我发现最好的方法是创建一个尽可能类似于monit环境的环境,并从那里运行start/stop程序。

代码语言:javascript
复制
# monit runs as superuser
$ sudo su

# the -i option ignores the inherited environment
# this PATH is what monit supplies by default
$ env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh

# try running start/stop program here
$

我发现最常见的问题是与环境变量相关(尤其是PATH)或与权限相关的问题。您应该记住monit通常是以root用户身份运行的。

另外,如果您在monit配置中使用as uid myusername,那么您应该在执行测试之前更改为用户myusername

我希望这能有所帮助。

票数 94
EN

Stack Overflow用户

发布于 2010-12-14 20:59:02

在让monit处理所有事情之前,一定要经常仔细检查conf并手动监控进程。systat(1)、top(1)和ps(1)是计算资源使用和限制的好朋友。了解您监控的流程也很重要。

关于启动和停止脚本,我使用了一个包装器脚本来重定向输出并检查环境和其他变量。如下所示:

代码语言:javascript
复制
$ cat monit-wrapper.sh

#!/bin/sh
{
  echo "MONIT-WRAPPER date"
  date
  echo "MONIT-WRAPPER env"
  env
  echo "MONIT-WRAPPER $@"
  $@
  R=$?
  echo "MONIT-WRAPPER exit code $R"
} >/tmp/monit.log 2>&1

然后用monit表示:

代码语言:javascript
复制
start program = "/home/billitch/bin/monit-wrapper.sh my-real-start-script and args"
stop program = "/home/billitch/bin/monit-wrapper.sh my-real-stop-script and args"

你仍然需要弄清楚你需要在包装器中包含什么信息,比如进程信息、id、系统资源限制等等。

票数 38
EN

Stack Overflow用户

发布于 2017-06-05 03:16:22

您可以在详细/调试模式下通过将MONIT_OPTS="-v"添加到/etc/default/monit (不要忘记重新启动;/etc/init.d/monit restart)来启动Monit。

然后可以使用tail -f /var/log/monit.log捕获输出

代码语言:javascript
复制
[CEST Jun  4 21:10:42] info     : Starting Monit 5.17.1 daemon with http interface at [*]:2812
[CEST Jun  4 21:10:42] info     : Starting Monit HTTP server at [*]:2812
[CEST Jun  4 21:10:42] info     : Monit HTTP server started
[CEST Jun  4 21:10:42] info     : 'ocean' Monit 5.17.1 started
[CEST Jun  4 21:10:42] debug    : Sending Monit instance changed notification to monit@example.io
[CEST Jun  4 21:10:42] debug    : Trying to send mail via smtp.sendgrid.net:587
[CEST Jun  4 21:10:43] debug    : Processing postponed events queue
[CEST Jun  4 21:10:43] debug    : 'rootfs' succeeded getting filesystem statistics for '/'
[CEST Jun  4 21:10:43] debug    : 'rootfs' filesytem flags has not changed
[CEST Jun  4 21:10:43] debug    : 'rootfs' inode usage test succeeded [current inode usage=8.5%]
[CEST Jun  4 21:10:43] debug    : 'rootfs' space usage test succeeded [current space usage=59.6%]
[CEST Jun  4 21:10:43] debug    : 'ws.example.com' succeeded testing protocol [WEBSOCKET] at [ws.example.com]:80/faye [TCP/IP] [response time 114.070 ms]
[CEST Jun  4 21:10:43] debug    : 'ws.example.com' connection succeeded to [ws.example.com]:80/faye [TCP/IP]
票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3356476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档