0

I plan on enabling Monit on my production server with the below configuration. I'm completely new to Monit and wanted to hear from others on tips or if there were other directives I should consider to bolster my monitoring script based on your experience.

My server is CentOS 5.6.

Thanks!

#httpd----
check process httpd with pidfile /var/run/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if 5 restarts within 5 cycles then timeout

#mysqld----
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if 5 restarts within 5 cycles then timeout

#postfix----
check process postfix with pidfile /var/spool/postfix/pid/master.pid
start program = "/etc/init.d/postfix start"
stop program  = "/etc/init.d/postfix stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if 5 restarts within 5 cycles then timeout

1 Answer 1

5

I have an extra line in my Postfix section for monit:

if failed port 25 protocol smtp then restart

Depending on what's being served by Apache, you can test on a request (e.g., request "/monit_token") instead of a plain HTTP response. The request can be something that hits your app directly, rather than just a static file. Again, it depends on what you're doing.

Since you have Postfix in there, you should consider how Monit alerts are actually going to get off the box in case Postfix is down. In my case, I'm doing a set mailserver gmail-smtp-in.l.google.com and sending the mail to a gmail account, so that I'm not relying on the functionality of my own mail server to get alert email out to me. I also have a gmail filter that will forward the alert message to an SMS gateway, so I get a text.

I also have something like this configuration:

check file alerttest with path /.monit_is_running
  alert [email protected] with reminder on 1440 cycles

There is no file /.monit_is_running so this alert will always trigger about once a day. This is a heartbeat for monit itself, so I know that it's running (a sort of "who watches the watchers" thing). This is an idea I got from someone on Serverfault, actually, but I don't remember who off-hand.

5
  • Thanks for the feedback. For Postfix, I use it as a null client or for outbound emails only, so I might be better off monitoring the master.pid instead of port 25 (i'm assuming outbound connections use a different port) Aug 24, 2012 at 23:03
  • @user1322092 If it's just for outbound, then, yes, it's sufficient to monitor the master PID.
    – cjc
    Aug 25, 2012 at 3:07
  • Sorry, I'm new to Monit. Is timeout directive essentially unmonitoring, or instead does monit timeout monitoring the service for a certain number of cycles? If the former, how is this different from the unmonitor directive? Aug 25, 2012 at 16:20
  • I found one enhancement: in Apache config, delete "protocol http" since I didn't care to monitor HTTP status code (if apache returns 403, monit throws a "connection error" even though web server is running). My server doesn't have a website yet. Aug 25, 2012 at 19:03
  • I believe the timeout causes unmonitoring, but it's been a little while, so I'm not sure without looking at the docs.
    – cjc
    Aug 26, 2012 at 3:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .