This site uses cookies and by using the site you are consenting to this. We utilize cookies to optimize our brand’s web presence and website experience. To learn more about cookies, click here to read our privacy statement.

Customize the Nagios Docker Plugin to Monitor Your Infrastructure

Author: Ming Li Posted In: DevOps

There are many cases where users want to monitor Docker running on their data center. Monitoring your infrastructure will alert your DevOps or Agile teams in case there’s problems – essential to any continuous integration or continuous delivery solutions.

However, not every organization has the budget for enterprise software that can provide this service. That’s where Nagios XI comes in. Nagios core is an open source free to use software. However, it does not offer Docker monitoring functionality by default, so that’s where this blog post can help. I will show how to create a customized plugin to monitor Docker for Nagios core edition.


  1. Have a working Nagios core monitor system with NRPE setup
  2. Have a running Docker stack

On client side

  1. Create a bash script check_docker.sh that collect info about docker status on client server.

The script gathers information about the docker environment. Variable INCIDENT will be assigned to any docker services that is currently not up and running. Variable NUM_SERVICES will get all the service that is created.

Nagios determines the status of a host or service by evaluating the return code from plugins. Here’s a list of valid return codes:

  • 0 – Service is OK.
  • 1 – Service has a WARNING.
  • 2 – Service is in a CRITICAL status.
  • 3 – Service status is UNKNOWN.

In the example above, exit code 1 or 0 will be returned based on the condition evaluation.

Next steps

  1. Save this script in /usr/lib/nagios/plugins (this directory may be different depending on your configuration).
  2. Modify the permission of the file to allow execution.
    #> sudo chmod +x /usr/lib/nagios/plugins/check_docker.sh
  3. Add this line into /etc/nagios /nrpe.cfg file by:
    #> echo “command[docker_services_check]=/usr/lib/nagios/plugins/docker_services_check.sh” >> /etc/nagios /nrpe.cfg
  4. Restart the NRPE listener:
    #> sudo systemctl restart nagios-nrpe-servder.service

Steps for the server side

  1. In /usr/local/nagios/etc/objects/commands.cfg file, add below lines:

2. In /usr/local/nagios/etc/objects/linuxbox.cfg file, add below lines:

Note: modify the host_name value based on your configuration.

3. Check the configuration and, if no errors or warnings, reload the service:
#> /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#> sudo systemctl reload-or-restart nagios.service

These steps will help you moving forward in monitoring Docker, allowing you to supervise hosts and their services in a much simpler way.