我发现调试monit是一件很痛苦的事情。Monit的shell环境基本上没有任何内容(没有路径或其他环境变量)。而且,我找不到日志文件。
问题是,如果monit脚本中的start或stop命令失败,就很难辨别出它出了什么问题。通常,这并不像在shell上运行命令那么简单,因为shell环境与monit shell环境不同。
人们用来调试monit配置的一些技术是什么?
例如,我很乐意有一个monit shell,用来测试我的脚本,或者用一个日志文件来查看哪里出了问题。
发布于 2011-01-18 08:29:18
我也遇到过同样的问题。使用monit的详细命令行选项有点帮助,但我发现最好的方法是创建一个尽可能类似于monit环境的环境,并从那里运行start/stop程序。
# 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。
我希望这能有所帮助。
发布于 2010-12-14 20:59:02
在让monit处理所有事情之前,一定要经常仔细检查conf并手动监控进程。systat(1)、top(1)和ps(1)是计算资源使用和限制的好朋友。了解您监控的流程也很重要。
关于启动和停止脚本,我使用了一个包装器脚本来重定向输出并检查环境和其他变量。如下所示:
$ 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表示:
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、系统资源限制等等。
发布于 2017-06-05 03:16:22
您可以在详细/调试模式下通过将MONIT_OPTS="-v"添加到/etc/default/monit (不要忘记重新启动;/etc/init.d/monit restart)来启动Monit。
然后可以使用tail -f /var/log/monit.log捕获输出
[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]https://stackoverflow.com/questions/3356476
复制相似问题