So you have developed and deployed a fresh new project and you want to be alerted in case an error happens.
Here’s how you do it using the M/Monit tool.
It can be installed on an Ubuntu machine using the following command:
sudo apt-get install monit
Now edit the /etc/monit/monitrc
configuration file and add the following:
set mailserver smtp.sendgrid.net port 587 username "USERNAME" password "PASSWORD" set alert YOUR_EMAIL@HOST.COM not on { instance, action } set httpd port 2812 and use address localhost # only accept connection from localhost allow localhost # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit' check file error.log with path /var/log/apache2/error.log if match "error" then alert check file prod.log with path /var/www/sfproject/app/logs/prod.log if match "request.CRITICAL" then alert
First we need to tell M/Monit what mail server to use (we used Sendgrid but you can use whatever you want), then to specify the email address which will receive the alerts. We also have to allow connections from localhost so the status
command below can be executed.
The actual monitoring is set up in the last two blocks of code, one for the apache error log and the next for the Symfony production logs. Anytime the specified string will appear in the logs, an alert email will be sent to the address we defined above.
To enable the changes, reload configuration:
monit reload
You can now check the status with the command:
monit status
It’s that simple!