# Docker swarm monitoring

# Introduction

Docker allows us to deploy applications in an agile, dynamic, precise and simple way. With Docker Swarm these applications will run as services, being able to balance the load dynamically.

The Docker services monitoring plugin allows to visualize in Pandora the status of these services, as well as the statistics of resource usage by the containers deployed in the local docker.

The docker\_services plugin will scan the swarm, retrieving the list of services, tasks and nodes through the methods provided by the docker commands.

With the collected data, XML will be sent to Pandora FMS, to represent the swarm nodes as agents.

Once the node agents are created, it will be created via API as many cluster views as services have been found.

Using the API, the resources will be linked, the pertinent agents will be created, and the monitoring modules of the services will be added.

# Compatibility matrix

Developed using docker 18.03.1-ce

# Prerequisites

Required:

● Requires launching from the MANAGER (or REACHABLE ) node of the docker swarm.  
● Can be launched from remote machines using docker\_machine .

Pandora FMS API connectivity is required.

[https://wiki.pandorafms.com/index.php?title=Pandora:Documentation\_es:Anexo\_API\_external](https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_es:Anexo_API_external)

Connection with the Tentacle service associated to your Pandora FMS server (for local executions of the plugin) is required under the following conditions:

● If you have as\_server\_plugin enabled.

The deployment of this plugin by binaries does not require any special requirements.

The script requires the PandoraFMS::PluginTools.pm library.

This library is available with the installation of the Pandora FMS OpenSource package.

You can download the latest version from:

[https://github.com/pandorafms/pandorafms/blob/develop/pandora\_server/lib/PandoraFMS/PluginTools.pm](https://github.com/pandorafms/pandorafms/blob/develop/pandora_server/lib/PandoraFMS/PluginTools.pm)

# Configuration

```
# Launch a pre-command before invoke docker commands
pre_command = eval $(docker-machine env ml1)
docker = docker
# Log file
log_file = /tmp/pandora_docker.log
# Show all modules instead only those with values
all_modules = 1
```

**pre\_command**  
Configures an environment preload command prior to executing commands to extract information. Set the following content if using docker\_machine : pre\_command = eval $(docker-machine env node\_name)  
**docker**  
Location of the complete docker binary, if it exists in the system PATH you can leave the default value 'docker'.  
**log\_file**  
Location and name of the log file to be used by the plugin **all\_modules**  
As many modules will be generated as possible states exist for the tasks with their respective value if this parameter is active (1). If it is deactivated (0), only the modules of tasks whose status has been reached will be shown. For example, if we have the parameter deactivated and the number of tasks in pending status is 0, this module will not be shown.

**General configuration**

```
# Agent configuration
agent_interval = 300
agent_group = Unknow
agent_group_id = 10
# Module interval
module_interval = 1
#module_tags = docker,services
module_group = Docker
# Pandora API configuration
api_url = http://nova.lab.artica.lan/pandora_console/include/api.php
api_user = admin
api_user_pass = pandora
api_pass = pandora
# Pandora FMS API flow process timeout (seconds)
api_timeout = 10
api_retries = 3
```

**agent\_interval**  
Sets the agent interval value.  
**agent\_group**  
Sets the group of the agents and cluster views that will be created in Pandora FMS Console.  
**agent\_group\_id** Set manually an id to the group.  
**module\_interval**  
It is a multiplicative factor of the agent interval value. It defines the execution interval of the modules. It will avoid that the modules go to unknown if we have that the plugin execution interval is bigger than the agent interval.  
**module\_tags**  
Defines the list of tags that will be applied to the modules generated by the plugin. They should be previously defined in Pandora FMS.  
**module\_group**  
Defines the module group in which the modules generated by the plugin will be classified. It must be previously defined in Pandora FMS.  
**api\_url**  
Defines the url where to access to the Pandora FMS console API.  
**api\_user**  
Defines the user with access to the API.  
**api\_user\_pass**  
Password of the user with access to the API.  
**api\_pass**  
Pandora FMS console API password.  
**api\_timeout**  
Sets the maximum time the plugin will spend trying to retrieve information from the Pandora FMS API.  
**api\_retries**  
Sets the maximum number of retries in Pandora FMS API calls.

**Execution modes and data transfer**

```
# Pandora Server configuration
mode = tentacle
tentacle_ip = nova.lab.artica.lan
tentacle_port = 41121
tentacle_opts =
tentacle_client = tentacle_client
local_folder = /var/spool/pandora/data_in
temp = /tmp
```

**mode**  
XML file transfer mode, can be:  
● local: copies the files to local\_folder  
● tentacle: transfer the files to tentacle\_ip via tentacle\_port  
**tentacle\_ip**  
IP address or FQDN where Pandora FMS is working.  
**tentacle\_port**  
Port where the Tentacle service associated to your Pandora FMS server is listening.  
**tentacle\_opts**  
Extra options for the Tentacle client.  
**tentacle\_client**  
Path where to find the tentacle client binary.  
**local\_folder**  
Location to move files to in local mode.  
**temp**  
Temporary location to store files before sending them.

# Manual execution

To run the plugin, configure the configuration file according to the instructions above.

Execution of the plugin:

Binary version:

```
./docker_services.64 docker_services.conf
```

Code version without libraries deployed:

```
perl -I lib pandora_mysql.pl pandora_mysql.conf
```

Where, lib is a directory containing the PandoraFMS folder containing the PluginTools.pm library.  
**Note** : You can customize the options given by the configuration file by adding '-value field' after the call:

```
./docker_services.64 docker_services.conf -agent_interval 200
```

<div id="bkmrk-"></div>

# Programmed execution

Run as a server plugin, as module\_exec in an agent, or from the system cron.  
Possible results:

● if it returns 1, the result is correct.  
● other than 1, there has been an error and you should consult the program log.

# Modules generated by the plugin

The standard execution of this plugin will return the following modules by default (with all optional blocks enabled):

The following agents will be created:

● One agent per docker swarm node with the following modules:

○ \[service name\] state  
○ \[service name\] running  
○ Node availability  
○ Node status  
○ Node TLS status