
Monitoring Docker from Centreon
Well, I guess all of you have been getting like mushrooms Docker containers, ¿No? If even a dinosaur like me has a plague of them… Well, and, apart from enjoying them, if we use Centreon as a monitoring system for our organization, ya sabemos, to monitor them!
Let's start again by praising the script 'centreon_plugins.pl’ that we saw in Previous Posts and it serves for almost everything we may need. In this case, and thanks to the Docker API, we can use it to know the health of its containers, where we can also know the CPU usage in a granular way, Memory, IOPS read/write and network interface traffic. Among others, since we will also be able to know the health of the Docker node or its services.
Before anything, on every machine with Docker, we enable API access to Docker, We'll edit '/lib/systemd/system/docker.service’ and we will modify the following line:
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:4444
We restart the services and then verify that the API responds, the port we want, It would be interesting to enable a token or encrypt the channel:
sudo systemctl daemon-reload sudo systemctl restart docker curl -X GET http://localhost:4444/images/json
Now it is, from our Centreon we could start playing with 'centreon_plugins.pl', The first thing is to see the help and the ways we have, Run:
perl /usr/lib/centreon/plugins/centreon-plugins/centreon_plugins.pl --plugin=cloud::docker::Restapi::plugin --list-mode Modes Available: container-usage list-containers node-status service-status
Next, we will need to list the IDs of the containers and write them down, and then individually monitor each container:
perl /usr/lib/centreon/plugins/centreon-plugins/centreon_plugins.pl --plugin=cloud::docker::Restapi::plugin --mode=list-containers --hostname=DIRECCION_IP --port=PORT
and with little more, Let's create 2 Commands, we will need one to know the resource usage of each container and another Command to know the health of the Docker Node, or if we have Docker Services, Well, another third command. Staying:
- Command Name: 'centreon_plugins-docker_container-usage’
- Command Line: perl $CENTREONPLUGINS$/centreon-plugins/centreon_plugins.pl –plugin=cloud::docker::Restapi::Plugin –mode=container-usage –hostname=$HOSTADDRESS$ –port=$ARG 1$ –container-id=$ARG 2$ –warning-cpu=$ARG 3$ –critical-cpu=$ARG 4$ –critical-container-status='%{state} !~ /running/’
- Arguments: ARG1 will be the API port, ARG2 container ID, the ARG3 and ARG4 to alert us of CPU usage, Warning and Critical respectively, We can put more arguments for memory, Iops, net…
- Command Name: 'centreon_plugins-docker_node-status’
- Command Line: perl $CENTREONPLUGINS$/centreon-plugins/centreon_plugins.pl –plugin=cloud::docker::Restapi::Plugin –mode=node-status –hostname=$HOSTADDRESS$ –port=$ARG 1$
- Arguments: ARG1 the port of the Docker API.
We will create as many services as containers we have to control your resources, as well as how Docker nodes we have and know their health. We will associate these services with a Host that we will create based on a Linux template, so we will also take away the resources of the node. Well, since we fill in the names of each Service, Their arguments…
And as always, if we did it right and after recording and exporting the Centreon configuration we will have it in a jiffy! All Monitored Containers, no one will consume more than they should, in addition to having supervision and control of their resources, as well as the health of Docker nodes.
I hope you find them interesting, And if not, Sorry 😉 good, I intend to, Try to supervise as much as you can! I send you a hug and may you be very happy!