Jam*_*ead 90
我遇到了同样的问题.使用monit的详细命令行选项有点帮助,但我发现最好的方法是创建一个与monit环境尽可能相似的环境并从那里运行启动/停止程序.
# 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
$
Run Code Online (Sandbox Code Playgroud)
我发现最常见的问题是环境变量相关(特别是PATH)或与权限相关.你应该记住,monit通常以root身份运行.
此外,如果您as uid myusername在monit配置中使用,则应myusername在执行测试之前更改为用户.
我希望有所帮助.
tho*_*odg 35
在让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
Run Code Online (Sandbox Code Playgroud)
然后在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"
Run Code Online (Sandbox Code Playgroud)
你仍然需要弄清楚你想要在包装器中使用什么信息,比如进程信息,id,系统资源限制等.
您可以通过添加在详细/调试模式启动monit的MONIT_OPTS="-v",以/etc/default/monit(别忘了重新启动; /etc/init.d/monit restart).
然后,您可以使用捕获输出 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]
Run Code Online (Sandbox Code Playgroud)
默认情况下,monit会记录到系统消息日志中,您可以在此处查看发生了什么。
另外,根据您的配置,您可能会登录到其他位置
tail -f /var/log/monit
Run Code Online (Sandbox Code Playgroud)
http://mmonit.com/monit/documentation/monit.html#LOGGING
假设默认值(与我使用的monit的任何旧版本相同),您都可以像这样尾随日志:
CentOS的:
tail -f /var/log/messages
Run Code Online (Sandbox Code Playgroud)
Ubuntu:
tail -f /var/log/syslog
Run Code Online (Sandbox Code Playgroud)
Mac OSX
tail -f /var/log/system.log
Run Code Online (Sandbox Code Playgroud)
视窗
这是龙
但是出于病态的好奇心,我在搜索如何执行此操作时发现了一个neato项目:https : //github.com/derFunk/monit-windows-agent