Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to start a program (Resque) but it takes a bit of time before a pidfile is written. Thus, I think that Monit thinks the program hasn't started and starts one or two more programs before the before the pidfile of the first one is written.

How do I delay the time Monit checks again, just for this process? Or should I solve this in another way?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

How do I delay the time Monit checks again, just for this process?


What you are trying to achieve could be done via "SERVICE POLL TIME" feature of monit

Monit documentation says

Services are checked in regular intervals given by the

set daemon n

statement. Checks are performed in the same order as they are written in the .monitrc file, except if dependencies are setup between services, in which case the services hierarchy may alternate the order of the checks.

One of the method to customize service poll is

  1. custom interval based on poll cycle length multiple

EVERY [number] CYCLES

Example:

check process resque with pidfile /your/app/root/tmp/pid/resque.pid
   every 2 cycles

Or should I solve this in another way?


I also did initial attempt to monitor resque jobs with monit because monit is a very lightweight daemon but eventually settled with GOD. I know , I know GOD is more resource hungry in comparison to monit but in case of resque we found it to be a good match.

share|improve this answer
    
Thanks! I ended up using every x cycles. I just found the number that worked for me. –  Ramon Tayag May 27 '12 at 9:03

You can check a specific service on a different interval than the default...

See SERVICE POLL TIME in the Monit documentation.

An example for your Resque program would be to check on a different number of cycles:

check process resque with pidfile /var/run/resque.pid
   every 5 cycles

or from the examples section:

Some servers are slow starters, like for example Java based Application Servers. 
So if we want to keep the poll-cycle low (i.e. < 60 seconds) but allow some services to take its time to start, 
the every statement is handy:

 check process dynamo with pidfile /etc/dynamo.pid every 2 cycles
       start program = "/etc/init.d/dynamo start"
       stop program  = "/etc/init.d/dynamo stop"
       if failed port 8840 then alert

or you can leverage the cron-style checks.

check process resque with pidfile /var/run/resque.pid
   every 10 * * * *

or if you're experiencing a slow startup, you can extend the timeout in the service start command:

check process apache with pidfile /var/run/httpd.pid
       start program = "/etc/init.d/httpd start" with timeout 90 seconds
share|improve this answer
    
Thanks ewwhite, this is useful too. –  Ramon Tayag May 27 '12 at 13:41
    
Same answer, right? –  ewwhite May 27 '12 at 14:11

You can also check if something have failed for X times straight:

 if failed 
    port 80 
    for 10 cycles 
 then alert

Or for X times within Y polls:

 if failed 
    port 80
    for 3 times within 5 cycles 
 then alert

Or both:

 check filesystem rootfs with path /dev/hda1
  if space usage > 80% for 5 times within 15 cycles then alert
  if space usage > 90% for 5 cycles then exec '/try/to/free/the/space'

(from here)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.