Feature request: add support for monitoring Docker containers?
It looks like doing this "in reverse" is already being investigated, i.e. using Monit as an init replacement in containers, but I was looking to do the reverse: I want to monitor containers from the host with Monit. That makes more sense to me.
It would be nice to be able to do something like this:
check container <monit name> with name <container name | ID>
...
Monit could check the container state from the Docker daemon and alert / restart / etc as necessary.
This should be very straightforward as Docker has a HTTP/JSON remote API that you can use for everything: querying container state/stats and starting/stopping/restarting them.
API documentation: Docker docs
I already managed to "hack" something like this by using "check host" (because you generally always run network services in containers) as in:
check host mycontainer with address 127.0.0.1
start program = "docker start ..."
stop program = "docker stop ..."
restart program = "docker restart ..."
if failed port 1234 protocol http then restart
but that's not the most elegant solution.