I'm having trouble with monit. I have setup monitoring with monit. However, I'm having trouble with a check for the process running. If the process is not running, i want to run an specific script that will create a pagerduty alert.

My Monit file looks like this:

check process "myapp" matching "myapp"
  start program = "/usr/local/myapp start"
  stop program  = "/usr/local/myapp stop"
  if does not exist then exec "/bin/bash pagerduty_script 'MyApp Down' trigger"

The pagerduty_script is just a wrapper that takes two arguments "string event" and action trigger

The script works. I've tested in terminal and it runs fine. events are actually created in pagerduty. However, it doesn't seem like monit is actually running it even though no process is running:

ps -ef | grep myapp
vagrant  23950 23136  0 17:40 pts/0    00:00:00 grep --color=auto myapp

sudo monit status:

Process 'myapp'
  status                            Execution failed
  monitoring status                 Monitored
  data collected                    Tue, 16 Sep 2014 17:40:11

I don't understand why it works on the console, but monit doesn't actually generate the event. Any help would be greatly appreciated!

  • Check your assumptions about the environment. Monit is running as a services. The PATH may be different, and many other things stored in the environment may be different. – Zoredache Sep 16 '14 at 18:08
  • I've also tried running with a full path if does not exist then exec "/usr/local/bin/pagerduty_script 'MyApp Down' trigger" But this doesn't work. I'm not sure what other things i could try. – roloenusa Sep 16 '14 at 18:14
  • I'm running on version 5.3.2 for Ubuntu. I don't know if that makes any difference. I can't find the release notes for this specific version to see if this is even a supported command. :/ – roloenusa Sep 16 '14 at 21:44
  • Have you read the man monit? That is basically all the docs there are for monit. The documentation the monit web site is just the most recent version of the man file. – Zoredache Sep 16 '14 at 22:13
  • BTW, have you considered just pointing your start program at your script, or a script that sends your alert, then tries to re-start your program? – Zoredache Sep 16 '14 at 22:15

I have been facing a similar problem and I figured out that the pagerduty script creates a temp file for the trigger and if this is file is modified not more than 4 hours ago, it doesn't re-trigger the alert.

It may have been the case that when you executed from the console, you have already create a temp file. You can verify this by deleting the temp file just before monit is expected to trigger an alert.

The other option is to use different unique event type to just test it out.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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