How to monitor an Apache web server using Monit
Monit is a tool that can monitor your Apache web server, MySQL database, or other daemon process. It can restart the service based on configurable conditions such as CPU usage, memory usage, number of children, etc. It can log status to a file, email status, and it has a web interface for monitoring or restarting the service. Here are the steps I took to install and configure the Monit tool on Ubuntu Hardy. It merely monitors the status of my Apache web server and restarts it if it stops. It also checks if the memory used by Apache is greater than 1 MB and logs it in /var/log/monit.log. For more configuration options, see the examples in the default /etc/monit/monitrc
file or the configuration examples in the monit documentation. I also found Ubuntu Geek's guide to be very helpful.
- Install monit
$ sudo apt-get install monit
- Edit the config file
$ sudo nano /etc/monit/monitrc
Insert the following:# check services every 2 minutes set daemon 120 # logging set logfile /var/log/monit.log # web interface set httpd port 2812 and use address localhost # only accept connection from localhost allow localhost # allow localhost to connect to the server allow admin:monit # require user ‘admin’ with password ‘monit’ # monitor apache check process apache2 with pidfile /var/run/apache2.pid start program = "/etc/init.d/apache2 start" if totalmem > 1.0 MB for 2 cycles then alert
- Check the file syntax
$ sudo monit -t
- Enable the service
$ sudo nano /etc/default/monit
Change the following line:startup=1
- Start monit
$ sudo /etc/init.d/monit start
- Point your browser at http://localhost:2812 and log in using the user "admin" and the password "monit".
- Click on "apache2" and you can see information about the Apache process.
Comments
Thank you for taking the time to put this together - the information is excellent but most of all accurate. I was able to get this up and running on Ubuntu 10.04 LTS in mere minutes.
Appreciate your efforts!
Thank you for the info and the soluion you provided. I have also tested it (Ubuntu 10.10) and got it to work aswell!
Another way of doing this is to register a free account from https://www.monitorscout.com and setup Apache/SQL monitoring from them.
I am now evaluating both options.