1. Simple URL Check
check host elastic_health_check with address 0.0.0.0 if failed url http://0.0.0.0:9200/_cluster/health for 2 cycles then alert
2. URL with Basic Authentification
# http://stackoverflow.com/questions/1115816/monit-and-apache-site-behind-http-basic-auth # It seems to be possible to include the credentials in the URL, have you tried this?: # (from http://mmonit.com/monit/documentation/monit.html#connection_testing ) # If a username and password is included in the URL Monit will attempt to login at the server using Basic Authentication. # http://user:password@www.foo.bar:8080/document/?querystring#ref check host hacker_news with address news.ycombinator.com if failed url http://username:password@www.myserver.com/search?q=123 and content = "successfully logged in" then alert
2. URL Checks – Dealing with Redirects
check host www.mix.com with address www.mix.com IF FAILED URL http://www.mix.com/blog/future.html content == "301 Moved Permanently" then alert IF FAILED URL http://www.mix.com/blog/future.html content == "Location: https://www.mix.com/blog/future.html" then alert IF FAILED URL https://www.mix.com/blog/future.html content == "mixalot" then alert
3. Simple URL and Content
check host hacker_news with address news.ycombinator.com
if failed url http://news.ycombinator.com/
and content = "hacker"
then alert
4. Multiple URL and Content
# http://bjdean.id.au/wiki/MonitSystemMonitoring
check host hacker_news with address news.ycombinator.com
if failed url http://www.youtube.com/results?search_query=elasticsearch
and content = "elasticsearch" and content = "results"
then alert
5. Comprehensive Health Check
# http://www.mathieu-elie.net/simple-and-usefull-monit-conf-for-elasticsearch/
check host elasticsearch_connection with address 0.0.0.0
if failed url http://0.0.0.0:9200/ with timeout 15 seconds then alert
group elasticsearch
check host elasticsearch_cluster_health with address 0.0.0.0
if failed url http://0.0.0.0:9200/_cluster/health
and content == 'green'
with timeout 60 seconds
then alert
group elasticsearch
6. HTTP Path Check
# http://mmonit.com/monit/documentation/monit.pdf
#You can use monit to monitor and test services running on a remote host.
check host rhn.redhat.com with address rhn.redhat.com
if failed port 80 protocol http and request "/help/about.pxt"
then alert with the mail-format {subject: RedHat is down again!}
if failed port 443 type TCPSSL and protocol http
with timeout 15 seconds then alert
7. Checks Using Send and Expect
# http://nongnu.13855.n7.nabble.com/monit-Question-about-cpu-monitoring-and-quot-expect-quot-behaviour-td3981.html
set expectbuffer 6 KB
if failed host localhost port 80
send "GET /blabla HTTP/1.1\r\n\r\n"
expect "(.{250}){20,}"
8. More Using Send and Expect
# for testing a HTTP server using send/expect strings instead of the built-in HTTP protocol test:
check host tildeslash.com with address tildeslash.com
if failed port 80
send "GET / HTTP/1.0\r\nHost: tildeslash.com\r\n\r\n"
expect "HTTP/[0-9\.]{3} 200 .*\r\n"
9. Yet Another Check Using Send and Expect for Checking the URL Status Code
if failed host cave.persia.ir port 4040
send "Open, Sesame!\r\n"
expect "Please enter the cave\r\n"
send "Shut, Sesame!\r\n"
expect "See you later [A-Za-z ]+\r\n"
then alert
if 5 restarts within 5 cycles then timeout
10. External Program to Check URL Status Code
cat /var/monit/conf.d/http_checkcode.sh:
#!/bin/bash
#wget --server-response http://localhost/nx.file 2>&1 | awk '/^ HTTP/{print $2}'
wget --server-response "$1" 2>&1 | awk '/^ HTTP/{print $2}'
check program check_url with path "/var/monit/conf.d/http_checkcode.sh http://www.google.com"
if status == 502 then restart
11. Use Inline Script to Check URL Status Code
check program check_url with path "wget --server-response http://localhost/nx.file 2>&1 | awk '/^ HTTP/{print $2}'"
if status == 502 then restart
12. Using script external program for HTTP checks
# http://lists.gnu.org/archive/html/monit-general/2012-11/msg00005.html
check process nginx
with pidfile /dh/nginx/servers/httpd-myserver/var/logs/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed host www.mysite.org port 80 protocol HTTP then restart #set your server IP that runs nginx
if 5 restarts with 5 cycles then alert
#cat /usr/local/bin/myhttptest.sh
#!/bin/bash
#exit `curl -sL -w "%{http_code}\\n" "http://mymachine" -o /dev/null`
check program myhttptest with path /usr/local/bin/myhttptest.sh
if status == 502 then restart
depends on nginx
13. FTP check
check host up2date with address 66.187.224.51 # This is ftp.redhat.com
if failed port 21 protocol ftp
then exec "/usr/bin/snpp -m
'Monit: $MONIT_EVENT for $MONIT_SERVICE' rladams"
Refences
1. http://www.unix.com/shell-programming-and-scripting/148595-capture-http-response-code-wget.html
2.
http://comments.gmane.org/gmane.comp.monitoring.monit.general/6459