Use Monit on AWS and Ubuntu

Examples

# Monit local http process
check process httpd with pidfile /var/run/httpd/httpd.pid
start program = "/usr/bin/systemctl httpd start"
stop program = "/usr/bin/systemctl httpd stop"
if children > 250 then restart
if 3 restarts within 5 cycles then timeout

# Monit local endpoint
check host phisaver with address phisaver.com
start program = "/bin/systemctl start httpd"
stop program = "/bin/systemctl stop httpd"
if failed
port 80
protocol http
method GET
content = ".*phisaver.*"
for 2 cycles
then restart

# Monit influxdb
check host influxdb with address live2.phisaver.com
start program = "/bin/systemctl start influxdb"
stop program = "/bin/systemctl stop influxdb"
if failed
port 8086
protocol http
username ******
password ******
method GET
request "/query?q=SHOW DATABASES"
for 2 cycles
then restart

# Monit ngnix
check process nginx with pidfile /run/nginx.pid
start program = "/bin/systemctl start nginx" with timeout 60 seconds
stop program = "/bin/systemctl stop nginx "
if failed host 127.0.0.1 port 80
protocol http
content = ".grafana."
for 3 cycles
then restart
# monit remote endpoint
check host live2-phisaver with address live2.phisaver.com
if failed port 80 protocol http
and request / with content = "Grafana"
then alert

Installation

Unfortunately, AWS (ec2) doesn’t come with monit available via:

sudo yum install monit # ain't gunna work on AWS

So we need to do the following:

tar zxvf monit-x.y.z-linux-x64.tar.gz (x.y.z denotes version numbers)
cd monit-x.y.z
cp bin/monit /usr/local/bin/
cp conf/monitrc /etc/

Check it’s running. When running, be sure to use sudo (root):

sudo /usr/local/bin/monit status

The gallery was not found!

One thought on “Use Monit on AWS and Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *