Simple HTTP/TCP health check for MongoDB

后端 未结 3 414
轻奢々
轻奢々 2021-02-05 11:16

I need to create a Health Check for a MongoDB instance inside a Docker container.

Although I can make a workaround and use the Mongo Ping using the CLI, the best option

3条回答
  •  梦谈多话
    2021-02-05 11:58

    If you need only a simple "ping" then you can also use curl:

    curl --connect-timeout 10 --silent --show-error hostname:27017
    

    If you get the "error" It looks like you are trying to access MongoDB over HTTP on the native driver port. then your MongoDB is running and reply an answer.

    Or use

    mongo --norc --quiet --host=hostname:27017 <<< "db.getMongo()"
    

提交回复
热议问题