Docker Swarm

Middleware monitors Docker Swarm clusters by running the Middleware Linux agent on every node in the swarm, both managers and workers, with one agent per node. Each agent monitors its own node and all the Swarm service tasks running on it.

On each node, the agent automatically collects:

  • Host metrics for the node (CPU, memory, disk and network).
  • Container metrics for every container running on the node, including Swarm service tasks.
  • Container logs from /var/lib/docker/containers.
  • Applications running in Swarm service tasks, auto-discovered along with their programming language, which you can instrument with zero-code OBI instrumentation without changing or rebuilding your images.

Install the agent on each node directly rather than deploying it as a Swarm service. The agent needs direct access to the host's processes, file system and network, which Swarm services do not provide.

Prerequisites#

  1. Swarm nodes running a supported Linux distribution.
  2. Outbound HTTPS access (port 443) from every node to your Middleware account.

Installation#

1 Install the agent on every node#

Run the Linux agent installer for your distribution (DEB or RPM) on every manager and worker node in the swarm.

To make sure new nodes are monitored as soon as they join the swarm, add the installation command to your node provisioning, for example cloud-init, Ansible or your VM image.

Optionally, tag each node with its swarm so you can filter by cluster in Middleware:

1MW_HOST_TAGS="swarm:production"

2 Verify the installation#

On each node, check that the agent is running:

1sudo systemctl status mw-agent

In Middleware, go to Infrastructure and confirm every swarm node appears as a host with its containers.

3 Instrument your Swarm services#

Choose one of the following options to collect traces from the applications running in your Swarm services.

Instrument applications without changing or rebuilding their images. On each node, list the discovered applications and instrument them with OBI:

1sudo mw-agent services list
2sudo mw-agent instrument --type obi --language java <SERVICE_NAME>

Run the instrument command on every node where the service has running tasks. See Zero-Code Instrumentation with OBI for requirements and details.

If you instrument your application with a Middleware or OpenTelemetry language agent or SDK, send traces to the agent running on the same node. The agent listens for OpenTelemetry data on ports 9319 (gRPC) and 9320 (HTTP) on every node.

Set MW_AGENT_SERVICE to an address of the node that the container can reach. For containers attached to overlay networks, this is the gateway of the docker_gwbridge network, which you can find by running:

1docker network inspect docker_gwbridge --format '{{ (index .IPAM.Config 0).Gateway }}'

For example, in your stack file:

1services:
2  my-app:
3    image: my-app:latest
4    environment:
5      - MW_AGENT_SERVICE=172.18.0.1

Uninstall#

To stop monitoring a node, uninstall the Linux agent from it.