Ram*_*Ram 4 linux monitoring services
如何监控 linux 服务的运行时间和停机时间。
我使用 chkconfig (RHEL 6.3) 为我的应用程序创建了一个服务。我想监视服务何时启动和停止。
我可以通过在提供时写入日志文件来监视服务,service test start/stop但是如果它崩溃或异常终止,这不会捕获我的应用程序。
如果你想监控不同服务器上的许多应用程序,那么去 NagiOS,如果你想监控特定的应用程序、文件所有权,那么就去 Monit。
监视在本地主机上运行的守护进程或类似程序。Monit 对于监视守护进程特别有用,例如在系统启动时从 /etc/init.d/ 启动的进程。例如sendmail、sshd、apache 和mysql。
与许多监控系统不同的是,如果发生错误情况,Monit 可以采取行动,例如;如果sendmail 没有运行,Monit 可以自动再次启动sendmail 或者如果apache 使用了太多资源(例如,如果正在进行DoS 攻击)Monit 可以停止或重新启动apache 并向您发送警报消息。Monit 还可以监控过程特性,例如;进程使用了多少内存或 CPU 周期
更新::配置部分
Monit 最容易通过 aptitude 或 apt-get 安装
sudo aptitude install monit
Run Code Online (Sandbox Code Playgroud)
monit 下载后,您可以将程序和进程添加到配置文件中
vim /etc/monit/monitrc
set daemon 3 # check services at 3-second intervals
set logfile /var/log/monit.log # you can see what monit is doing
set alert sysadm@foo.bar # receive all alerts
include /etc/monit.d/* # add monit script path
Run Code Online (Sandbox Code Playgroud)
然后为您的应用程序创建 monit 脚本,只需查看以下脚本示例:
您只需要/etc/monit.d/像这样创建 monit 脚本,/etc/monit.d/httpd.monit然后重新加载 monit 服务并检查 monit 日志tail -f /var/log/monit.log
对于阿帕奇
check process apache with pidfile /usr/local/apache/logs/httpd.pid
start program = "/etc/init.d/httpd start" with timeout 60 seconds
stop program = "/etc/init.d/httpd stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 200.0 MB for 5 cycles then restart
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if failed host www.tildeslash.com port 80 protocol http
and request "/monit/doc/next.php"
then restart
if failed port 443 type tcpssl protocol http
with timeout 15 seconds
then restart
if 3 restarts within 5 cycles then timeout
depends on apache_bin
group server
Run Code Online (Sandbox Code Playgroud)
对于 Safesquid 代理
# Check if the safesquid process is running by monitoring the PID recorded in /opt/safesquid/safesquid/run/safesquid.pid
check process safesquid with pidfile /opt/safesquid/safesquid/run/safesquid.pid
group root
start program = "/etc/init.d/safesquid start"
stop program = "/etc/init.d/safesquid stop"
mode active
# If safesquid process is active it must be updating the performance log at
# /opt/safesquid/safesquid/logs/performance/performance.log every 2 seconds.
# If the file is more than 3 seconds old we definitely have a problem
check file "safesquid-PERFORMANCELOG" with path /opt/safesquid/safesquid/logs/performance/performance.log
if timestamp > 3 SECOND then alert
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6307 次 |
| 最近记录: |