Monitoring Docker containers on an Ubuntu server using Icinga involves setting up the Icinga agent to execute Docker-specific monitoring checks and configuring the Icinga server to process and display these checks. Here is a step-by-step guide to achieve this.
Step 1: Install Docker Monitoring Plugin
On the Icinga Agent Server: You need to have a plugin that can monitor Docker. One common choice is the check_docker plugin, which can be found on GitHub. You will have to manually download and install this plugin.
$ cd /usr/lib/nagios/plugins
$ sudo wget https://exchange.icinga.com/elacheche/Docker%20containers%20check/files/12915/docker_check.py
$ sudo chmod +x docker_check.py
Install Python and Docker SDK for Python: The check_docker plugin requires Python and the Docker SDK for Python.
$ sudo apt-get update
$ sudo apt-get install python3 python3-pip
$ sudo pip3 install docker
# Update the apt package index and install packages to allow apt to use a repository over HTTPS: | |
$ sudo apt-get update | |
$ sudo apt-get install ca-certificates curl gnupg lsb-release | |
# Add Docker’s official GPG key: | |
$ sudo mkdir -p /etc/apt/keyrings | |
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
# Use the following command to set up the repository: | |
$ echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
# Install Docker Engine | |
$ sudo apt-get update | |
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin |
Step 2: Configure Icinga Agent
Add Command Definitions: You need to define a command in Icinga for the Docker check. Create or edit a configuration file in the Icinga agent:
sudo nano /etc/icinga2/conf.d/commands.conf
Add the following definition:
object CheckCommand "docker_check" {
command = [ "/usr/bin/python3", "/usr/lib/nagios/plugins/docker_check.py" ]
arguments = {
"--containers" = "$docker_containers$"
"--stats" = "$docker_stats$"
}
}
Step 3: Configure Icinga Server
Define Host Object: If not already done, define the host object for the Docker server in your Icinga server configuration:
object Host "docker-server" {
import "generic-host"
address = "docker-agent-ip"
check_command = "hostalive"
}
Define Service for Docker Monitoring: Create a service definition to monitor Docker:
apply Service "docker-status" {
import "generic-service"
check_command = "docker_check"
vars.docker_containers = "all"
vars.docker_stats = "true"
assign where host.name == "docker-server"
}
Reload Icinga 2: After configuring the service and command, reload Icinga 2 to apply the changes:
$ sudo systemctl reload icinga2
Step 4: Verify the Configuration
Icinga Web 2: Log into Icinga Web 2 and check the 'Services' section. You should see your new service for monitoring Docker. Ensure that it is reporting the status of Docker containers as expected.
Troubleshooting: If the checks aren't working as expected, look at the logs in /var/log/icinga2/icinga2.log for any errors. Check the permissions of the check_docker.py script and ensure that the Icinga user can execute it and has access to Docker via the Docker group.
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND