---
title: "Docker Swarm"
description: "Monitor Docker Swarm nodes, services and containers with the Middleware agent, and instrument Swarm services without changing or rebuilding images."
section: "Agent Installation"
breadcrumb: "Containers > Docker Swarm"
canonical: "https://docs.middleware.io/get-started/agent/docker-swarm"
---
# Docker Swarm

Middleware monitors Docker Swarm clusters by running the [Middleware Linux agent](/get-started/agent/linux) 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](/get-started/agent/linux#zero-code-instrumentation-with-obi) without changing or rebuilding your images.

> **Note:** 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](/get-started/agent/linux#supported-environments).
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](/get-started/agent/linux#installation) 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:

```bash
MW_HOST_TAGS="swarm:production"
```

#### 2 Verify the installation

On each node, check that the agent is running:

```bash
sudo 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.

#### Zero-code (OBI)

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

```bash
sudo mw-agent services list
sudo 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](/get-started/agent/linux#zero-code-instrumentation-with-obi) for requirements and details.

#### Language agents and SDKs

If you instrument your application with a Middleware or OpenTelemetry [language agent or SDK](/get-started/apm), 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:

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

For example, in your stack file:

```yaml
services:
  my-app:
    image: my-app:latest
    environment:
      - MW_AGENT_SERVICE=172.18.0.1
```

## Uninstall

To stop monitoring a node, [uninstall the Linux agent](/get-started/agent/linux#uninstall) from it.
