Technical Article => Software => Software design

With the popularity of Docker, more and more service have been moved into docker containers and they are easy to build up and maintain for each atomic service(though it's a bit complex to maintain multiple docker containers which contain different service to form a complete solution). Ideally, each docker container should only contain one service which has only one running process. However, in reality there would be cases multiple processes would run in one single docker container and there is a master process. In this case, to monitor all these processes would be a challenge task.

In cases where multiple processes exist in a docker container, the logic should be that the docker container would shut down if the master process is terminated and it should remain running if some assistant process is terminated and the assistant process should be automatically restarted. To maintain this kind of logic, there would be some process monitoring tool coming into the picture so that the monitoring tool will monitor all application processes and it would have a PID of 1 which the docker container cares about only.

There are a few monitoring tools available for developers to use. In this post, we will cover three of them : Supervisord, God and Monit.

Supervisord

Supervisord is a light weight process management system which can manage subprocesses specified in supervisord configuration file. It can be used to monitor processes and restart them in case the subprocess exits and it has event listener to listen to different events so that appropriate actions can be taken.

Pros

Light weight with enough features like restart, parallel starting, event listener, start retries etc

Memory friendly

Easy to configure and suitable for non-complicated management

It can be ran either in daemon mode or non-daemon mode. This makes it suitable for either container environment or normal environment

Nice documentation

Cons

Not too powerful

No process dependency management(Can use event listener to achieve this somehow)

Subprocess cannot be ran in daemon mode.

God

God is a powerful but complicated process management system which provides full control over how a program can be monitored. One can write a complex configuration file to control various levels of a program lifecycle. It is suitable for complex process management.

Pros

Powerful functions. Easily write your own custom conditions in Ruby

Easy to install

Supports both poll and event based conditions

Supports monitoring daemonized process(though you need to provide the PID file to it)

Cons

Complicated to configure

Memory heavy (Known memory leak issues)

It's written in Ruby. The configuration file would require you understand some Ruby.

Monit

Monit is a helpful program that automatically monitors and manages server programs to ensure that they not only stay online consistently, but that the file size, checksum, or permissions are always correct. It’s mostly used to manage services such as apache, sshd etc.

Pros

Easy to install and configure

Can monitor not only programs but also files, filesystems etc. For example, if file changes, it would know

Can monitor system resources such as CPU usage, memory usage etc

Web based UI provided to check status of processes

It can be ran either in daemon mode or non-daemon mode

Relative good documentation

Cons

Monit requires processes to create PID files. Hence it would not suitable for processes which don't create PID files while running such as shell script.

In conclusion, for normal application or service, Supervisord would be good enough given the features it has. But if you application becomes pretty complicated and many dependencies exist among different processes or sophisticated process monitoring is needed, God would be a better choice. If you want to monitor files, network apart from processes, you would consider about Monit.