Skip to content

Instantly share code, notes, and snippets.

@pasviegas
Created March 27, 2010 01:26
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save pasviegas/345611 to your computer and use it in GitHub Desktop.
Save pasviegas/345611 to your computer and use it in GitHub Desktop.
Simple monit script for mongodb
check host mongodb with address localhost
start program = "/usr/bin/sudo /opt/database/mongo/bin/mongod"
stop program = "/usr/bin/sudo /usr/bin/pkill -f mongod"
if failed port 28017 protocol HTTP
request /
with timeout 10 seconds
then start
@virajp
Copy link

virajp commented Apr 29, 2013

Does this work even if the MongoDB requires authentication ?

@dzamosenchuk
Copy link

I have problem. I try to use this config for monitoring my mongo service. But my mongo server has authentication and monit is failed. I've tried to use next variant:
if failed url http://admin:password123@mongo.server.com:28017/ for 1 cycles then alert
But it didn't work.
Do You have any ideas for fix it?

@artdokxxx
Copy link

Check port 27017 ; ) Ex.: if failed host x.x.x.x port 27017

@rseward
Copy link

rseward commented Aug 30, 2016

Centos 7 - mongod monit check snippit.

check process mongodb with pidfile /var/lib/mongo/mongod.lock
group database
start program = "/bin/systemctl start mongod"
stop program = "/bin/systemctl stop mongod"
if failed host 127.0.0.1 port 28017 protocol http
and request "/" with timeout 10 seconds then restart
if 5 restarts within 5 cycles then timeout

@madhavkaneriya
Copy link

My mongodb has been authenticated and monit is giving "failed to connect" error.
I am using following config,

check process mongodb matching "mongodb"
start program = "/usr/bin/sudo /bin/systemctl start mongodb"
stop program = "/usr/bin/sudo /bin/systemctl stop mongodb"
if failed url http://username:password@127.0.0.1:27017/authDb with timeout 10 seconds then restart
if 5 restarts within 5 cycles then timeout

@dzamosenchuk @virajp , Did any of you find any solution, Please let me know I am having same kind of issue.

@saiakash
Copy link

I succesfully configured my monit and it works fine.I think it will help someone.

check process mongodb with pidfile /var/lib/mongodb/mongod.lock

group database

start program = "/bin/systemctl start mongodb"
stop program = "/bin/systemctl stop mongodb"

if failed host localhost port 27017 then restart

@etcetc
Copy link

etcetc commented Mar 27, 2019

I cannot get the most basic script working on this on ubuntu 16.04 monit 5.16

check process mongod with pidfile /var/run/mongod.pid
  group database
  start program = "/usr/sbin/service mongod start"
  stop program = "/usr/sbin/service mongod stop"
  if failed host 127.0.0.1 port 27017 protocol http
    and request "/" with timeout 15 seconds then restart

I get the error: Error reading pid from file '/var/run/mongod.pid'

but when I run cat /var/run/mongod.pid I do get the value 51455

I've changed permissions making it both less and more restrictive to no avail. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment