# Docker container monitoring

> The Connect agent on your server checks that a Docker container is running and optionally healthy. Set it up in the dashboard.

A container can live on a server that is not reachable from outside. That is why the check is done by the Connect agent, which runs on your side and tells Upstat what state the container is in.

## What is checked

1. The Connect agent runs on your server and keeps a connection to Upstat. The agent opens the connection, so you do not have to let incoming traffic reach the server.
2. On every check Upstat asks the agent to look up the state of the container by its name.
3. The agent returns whether the container is running, whether it is healthy (if it has a healthcheck defined) and a text status.
4. The check passes if the container is running, and when the healthy requirement is on, also if it is healthy.

## How to set it up

1. In the dashboard open Connect agents and create a target. The agent key is shown only once, copy it.
2. The dashboard shows the agent configuration together with the key. The agent is built from the sk.upstat.connect repository and runs on your server.
3. Once the agent logs in, the target shows as online in the dashboard.
4. Create a Docker monitor: choose the target and enter the container name.

## Monitor settings

This is the configuration shape the checker reads. The monitor is also bound to one specific Connect agent.

| Monitor settings | Where to set it |
|---|---|
| **Connect target** (`connect_target_id`): The agent that performs the check. You pick it from your own Connect targets. | Dashboard, through the Connect agent |
| **Container name** (`container_name`): The container name as you see it in the Docker list. | Dashboard, through the Connect agent |
| **Require healthy** (`require_healthy`): Off by default, a running container is enough. When on, the agent must also report the healthy state. If it does not, the check fails. | Dashboard, through the Connect agent |

## Example agent configuration

The agent logs in to Upstat with the target and the key. The key is read from the environment variable whose name is set in auth_key_env.

Agent configuration

```
daemon_url = "wss://connect.upstat.sk"
target_id = "01J..."
auth_key_env = "UPSTAT_CONNECT_KEY"
```

## What counts as a failure

- The container is not running.
- Requiring healthy is on and the agent does not report the healthy state.
- The agent is not connected. The check then fails with an agent-unavailable error, so with the server or agent switched off you see DOWN.
- The agent returns an error, for example that the container does not exist.

## What happens on failure

- The monitor changes from UP to DOWN. If you use ignore blips, the failure first has to last for the time or the number of checks you set.
- An incident named after the monitor is created automatically. When a check passes again, the incident closes itself.
- Your alert rules send a message through the channels you set up: Slack, Discord, Telegram, email, SMS, push, webhook or ntfy.
- If the monitor is linked to a status page component, its state shows up there too.

## How it works with ignore blips

A short outage does not have to mean DOWN right away. For each monitor you can set state stabilization. Upstat decides it when it processes check results, not the checker.

- `consecutive_failures`: How many checks in a row must fail before the monitor is marked DOWN. For example 3 means three failures in a row.
- `min_down_seconds`: How long the failing has to last before the state changes to DOWN.
- `min_up_seconds`: How long everything has to be fine after an outage before the monitor goes back to UP. It protects against rapid flapping.

A container stops for a moment during a restart or deploy. The agent can also briefly lose its connection. A few failures in a row tell a real crash from a planned restart.

[How monitoring works](https://upstat.sk/en/how-monitoring-works)

## Limits by plan

The shortest allowed interval between checks depends on the plan. The numbers are read straight from the plan settings.

| Plan | Shortest check interval |
|---|---|
| Hobby | 120 s |
| Starter | 60 s |
| Pro | 30 s |

## Other monitor types

- [Website](https://upstat.sk/en/monitors/website)
- [SSL certificate](https://upstat.sk/en/monitors/ssl)
- [TCP port](https://upstat.sk/en/monitors/port)
- [Heartbeat](https://upstat.sk/en/monitors/heartbeat)
- [API endpoint](https://upstat.sk/en/monitors/api)
- [Database](https://upstat.sk/en/monitors/database)
- [How monitoring works](https://upstat.sk/en/how-monitoring-works): The check cycle, outage confirmation and monitor states.
- [Alerting](https://upstat.sk/en/alerting): Rules, thresholds and alert channels.
