# TCP port monitoring

> Checks whether a TCP connection to a given host and port succeeds. Useful for mail servers, databases, SSH and other services that are not websites.

The simplest availability check for a service: a connection to the host and port either opens or it does not. Use it wherever there is no website to send an HTTP request to.

## What is checked

1. The checker tries to open a TCP connection to the host and port.
2. If the connection is established, the check passed and the time it took is measured.
3. After the connection is made nothing is sent or read. The check confirms that the port is listening, not that the service behind it answers correctly.

## Monitor settings

The checker really reads all of this from the monitor configuration.

| Monitor settings | Where to set it |
|---|---|
| **Host** (`host`): A domain name or the IP address of the server. | Dashboard and REST API |
| **Port** (`port`): A port number from 1 to 65535, for example 22 for SSH or 25 for SMTP. | Dashboard and REST API |
| **Timeout** (`timeout_ms`): The longest time in milliseconds the checker waits for the connection. Without a value the checker default applies. | Dashboard and REST API |

## Example through the REST API

A monitor that checks every 5 minutes whether port 25 on a mail server is listening. The interval cannot be shorter than your plan minimum.

Port monitor configuration

```
{
  "name": "SMTP mail.example.com",
  "type": "port",
  "interval_seconds": 300,
  "config": {
    "host": "mail.example.com",
    "port": 25,
    "timeout_ms": 5000
  }
}
```

## What counts as a failure

- The connection is refused because nothing listens on the port.
- The host name cannot be resolved through DNS.
- The connection is not established within the timeout, for example because of a firewall.

## 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 port that closes for a few seconds while a service restarts is a typical blip. Requiring several failures in a row avoids an alert for every 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 |

## Questions about this type

### Does a port monitor also verify that a database or mail server answers correctly?

No. Only the TCP connection is checked. The answer of the application is not judged.

## Other monitor types

- [Website](https://upstat.sk/en/monitors/website)
- [SSL certificate](https://upstat.sk/en/monitors/ssl)
- [Heartbeat](https://upstat.sk/en/monitors/heartbeat)
- [API endpoint](https://upstat.sk/en/monitors/api)
- [Docker container](https://upstat.sk/en/monitors/docker)
- [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.
