【问题标题】:set up Delayed_job with monit monitoring tool使用 monit 监控工具设置 Delayed_job
【发布时间】:2011-12-25 02:29:41
【问题描述】:

我正在使用 ruby​​ 1.9.2p280 部署 Rubyonrails 网络应用程序,使用 apache 乘客和延迟作业作为后台作业的 ruby​​onrails 3.07。

我想监控我的乘客以及delayed_job 后台工作。

我找不到任何分步指南。

非常感谢

【问题讨论】:

  • 根据我使用 DelayedJob 的经验,我建议除非必须,否则不要使用它。如果您要部署到 Heroku,请使用它,因为这是可用的。但是,如果您能够设置自己的 cron 作业,那么只需将记录写入包含需要完成的操作的详细信息的表中,然后创建执行待处理操作的模块或类方法。设置一个 cron 作业来读取表并执行待处理的操作:rails runner "SomeModule.some_method"。我不确定这对您想要的监控意味着什么,但您最好不要使用 DelayedJob。
  • 我想监控我的webserver进程和delayed_job进程。如果它们达到某个内存点或 cpu 时间百分比,那么它们应该自动重新启动。 delay_job 和乘客的内存消耗随着时间的推移而增长,最终可能会有很高的交换使用率,导致它们变得无响应。
  • @Steve 为什么自己写的类比delayed_job处理得更好?为什么要花时间来开发而不是使用现有的和广泛使用的东西?!
  • @YoLudke 因为它实际上对你有用的东西很少,而且它为你做了一些事情,它的方式可能会给你带来麻烦并花费你更多的调试时间时间比自己编写它所花费的时间——在我看来,当然。

标签: ruby-on-rails-3 monitoring delayed-job monit


【解决方案1】:

添加下面提到的以下 .monitrc 文件并运行命令monit reload 以加载配置。

/etc/monit/web.monitrc

check process apache with pidfile /var/run/apache2.pid
  start program = "/etc/init.d/apache2 start"
  stop program  = "/etc/init.d/apache2 stop"
  if cpu > 80% for 5 cycles then restart
  if totalmem > 300.0 MB for 5 cycles then restart
  if children > 250 then alert
  if failed port 80 with timeout 10 seconds then restart
  if 3 restarts within 5 cycles then timeout
  mode manual
  group web

/etc/monit/delayed_job.monitrc

check process delayed_job with pidfile /mnt/<project>/tmp/pids/delayed_job.pid
  start program = "/usr/bin/delayed_job_start"
  stop program = "/usr/bin/delayed_job_stop"
  mode manual
  group delayed_job

/usr/bin/delayed_job_start

#!/bin/sh

cd /mnt/<project> && RAILS_ENV=production ruby script/delayed_job start

【讨论】:

  • 对不起,我问的是 apache,而不是 nginx。例如,我找不到任何帮助:如果 cpu 使用率 > 80% 持续 5 个周期,则重新启动。 5个周期是什么意思?
  • 已用 apache 更新了答案。周期数 = 监视器检查状态的次数。当monit连续5次检查发现apache进程的CPU使用率大于85%时,会重启apache。
  • 还有一个真正的快速问题,我在哪里找不到 apache2 的 pid 文件?我的系统中没有 /var/run/apache2.pid。怎么了 ?使用 monit 时,我是否必须从我的系统中停止 apache2 守护程序并让 monit 启动它?非常感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-16
  • 2017-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
相关资源
最近更新 更多