I had it enough today with my My Tomcat server which occasionally runs out of memory and crashes! Therefore, I decided to install a service to monitor Tomcat and notify me if anything goes wrong. I decided to install Monit, its installation is quite straight forward unless you, like me, make stupid typos. In that case, you have no idea for example WHY you do not receive alerts in your mailbox. After installing the required packages for your linux distribution, you need to change the config file to state what is it that you want to monitor. In my case, I’m monitoring the port 8080 as added in the monit.conf file:
set mail-format {from: gmailAccount}
check host MYHEALTHFRAME_TOMCAT address 104.238.100.249
alert EMAIL1
alert EMAIL2
if failed port 8080 protocol HTTP
request "/"
then alert
So basically if the request cannot be served from the port 8080, the stated emails will be notified. But don’t forget that you must mention the email server which Monit uses for sending messages. In my case, I use gmail. One extra note; if you are using gmail, you have to first login to gmail and accept the “less secure apps” option to be able to send emails remotely.
set mailserver smtp.gmail.com port 587
username "gmailAccount" password "PASSWORD"
using tlsv12
Once you’ve done this, you can enable the web-based administrator panel for Monit by adding these two lines.
set httpd port 2812
allow USERNAME:PASSWORD
You are good to go! Enjoy maintaining your service to the world!