# Connection records and traffic totals

> For the complete documentation index, see [llms.txt](https://docs.ringleader.dev/llms.txt).


> Ringleader counts a workstation's connections per day, so you can see why one failed, what the workstation reached and what happened to an injected credential.


Ringleader counts a workstation's connections per day, so you can see why one failed, what the
workstation reached and what happened to an injected credential. The count is made by the
Edge that serves the workstation, or by the
workstation's own
[network process](https://docs.ringleader.dev/security/outbound/enforcement/#network-processes-and-edge-vms)
where it has no Edge. This page says "the Edge" for either. It keeps a count per workstation and per
UTC day, not a log of connections.

## Record kinds

The Edge keeps four kinds of record. Each row below says what a record holds and when it exists.

| Record | Each row holds | Recorded |
|---|---|---|
| Refused connections | The destination and port, the reason, how many times it happened and when it last did. | Always, for a workstation that an Edge serves. |
| Allowed connections | The destination and port, the number of connections, and the bytes sent and received. | For a workstation whose policy is `audit`, or for every workstation the Edge serves when `records.allowed` is `true`. |
| Credential use | The Integration and the host, the number of requests, and how many got a `401` or `403` back. It also counts connections to a host whose credential did not resolve, where nothing was injected. | When an Integration injects a credential for the workstation. |
| Daily totals | The number of connections and the bytes in each direction, with no destination. | Always, for a workstation that an Edge serves. |

Nothing records a workstation that no Edge serves and that its own network process cannot serve.
That covers a cloud workstation with no Edge, a local workstation created before its provider gave
each workstation its own address, and a workstation that declares no egress policy and no injected
credential. For such a workstation, `rl workstation egress` says why it has nothing to show.

[Record retention](#record-retention) says how long records are kept.

## Allowed connections

An empty `--allowed` list does not prove that nothing was reached. When the workstation's
[`status.egress.recorded`](https://docs.ringleader.dev/reference/resources/workstation/#status-fields) lists `allowed`,
an empty list means no allowed connection fell in the window. When it does not, the command says
that recording may be off.

The Edge records allowed connections only when you ask, because the list comes close to a browsing
history of the workstation. You turn them on in one of two ways:

- A namespace administrator sets `records: {allowed: true}` on the Edge. Every workstation the
  Edge serves is then recorded, and shows `allowed` in its `status.egress.recorded`, whatever build
  the Edge runs.
- A workstation's policy is `enforcement: audit`. Only that workstation is recorded.
  [Audit recording](https://docs.ringleader.dev/security/outbound/reach-audit/#audit-recording) says
  when that recording starts and stops.

## Data that is never recorded

No record holds a credential, a header, a request or response body, or a URL path or query. DNS
lookups are not recorded. The connection that follows a lookup is, as a refused or an allowed
connection.

## Daily totals

Daily totals are what you read for usage and cost: how much traffic each workstation moved, per UTC
day. They name no destination, so they are kept whatever `records` says. A day's total includes the
bytes of connections that are still open.

Each total splits traffic in two ways:

- By who opened the connection. An outbound connection is one the workstation opened. An inbound
  connection is one opened to the workstation through the Edge's
  [management ports](https://docs.ringleader.dev/reference/resources/edge/#public-address-and-management-ports). Only a
  cloud Edge counts inbound connections. An older edge build reports zero for a day it never
  counted, so a day whose inbound counts are all zero prints as `not counted`.
- By direction. Egress bytes leave the workstation and ingress bytes enter it. They are kept apart
  because clouds price the two directions differently.

## Two byte counts

A workstation also reports how many bytes its own network interface sent and received each day. The
workstation's root user can change this number, so treat it as a usage figure, not a record. An hcs
workstation reports no number of its own, and neither does a workstation whose default route runs
through a tunnel inside it.

Ringleader never adds the two counts together, and one never stands in for the other. The commands
show them differently:

- `rl workstation egress --totals` shows one row per day. For a day with no Edge total, it shows the
  workstation's own number instead, and its `SOURCE` column says `box` rather than `edge`.
- `rl usage` shows both counts side by side, in the `EDGE-OUT` and `EDGE-IN` columns and in the
  `WS-OUT` and `WS-IN` columns. See
  [Edge bytes and workstation bytes](https://docs.ringleader.dev/reference/cli/commands/usage/#edge-bytes-and-workstation-bytes).

## Record access

Ringleader keeps the records of a cloud workstation itself. The records of a local workstation stay
on the computer it runs on. A member reads the records of the cloud workstations they own, and a
namespace administrator reads every cloud workstation's in the namespace. Nobody but the user of the
computer reads a local workstation's records, an administrator included. Turning recording on, in an Edge or in a WorkstationConfig, does not let you read
what it records.

## Record retention

Ringleader keeps each day's records for 90 days. To keep an Edge's records longer or shorter, a
namespace administrator sets `records.retention` on the Edge, as a duration from 7 to 400 days
(`180d`, `720h`):

```yaml
spec:
  records:
    retention: 180d
```

The window covers every kind of record that Edge writes, daily totals included. A window shorter
than 8 days keeps records for 8 days. A workstation with no Edge, such as one its own network
process serves, keeps the default. Daily totals from an Edge that sets no window are kept for
Ringleader's own totals window, which is 90 days unless the operator of your Ringleader changed it.

For each workstation and day, Ringleader keeps up to 10,000 allowed rows and 1,000 refused rows.
Past that limit, the rest of the day are counted together in one row that reads
`other destinations`, and
[`rl workstation egress`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-workstation-egress-workstation)
prints a note beside it. One read returns at most 1,000 rows.

## Read a workstation's connection records

The `rl workstation egress` command lists one kind of record for a workstation. It lists refused
connections unless you pass a flag for another kind.

1. List the connections Ringleader refused in the last 7 days:

   ```bash
   rl workstation egress my-box
   ```

   Each row shows a destination, the reason it was refused and when it last happened.
2. Optional: narrow the window to the last day:

   ```bash
   rl workstation egress my-box --since 24h
   ```

3. List what the workstation reached:

   ```bash
   rl workstation egress my-box --allowed
   ```

   The list is empty unless the workstation records allowed connections.
   [Turn on recording of allowed connections](#turn-on-recording-of-allowed-connections) shows how.
4. List what each Integration's credential did:

   ```bash
   rl workstation egress my-box --credentials
   ```

5. Optional: leave out the workstation name to read every workstation you may read. The output
   then adds a `FROM` column, which says where each row was kept, and a `BOX` column, which names
   the workstation.

[`rl workstation egress`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-workstation-egress-workstation)
lists every flag and column.

## Turn on recording of allowed connections

To record one workstation, give it an `audit` policy, as
[Workstation reach audit](https://docs.ringleader.dev/security/outbound/reach-audit/) shows.
To record every workstation an Edge serves, a namespace administrator turns recording on in the
Edge.

1. Add `records` to the `spec` of the Edge's file:

   ```yaml
   spec:
     records:
       allowed: true
   ```

2. Apply the file:

   ```bash
   rl apply -f edge.yaml
   ```

3. Check that a workstation the Edge serves is recording:

   ```bash
   rl workstation get my-box -o yaml
   ```

   Its `status.egress.recorded` lists `allowed` once recording is on.

## Read traffic totals

Read the bytes and connections a workstation moved each day with the `--totals` flag.

1. List the last 7 days of totals:

   ```bash
   rl workstation egress my-box --totals
   ```

   The output has one row per day.
2. Optional: read a longer window, such as the last 30 days:

   ```bash
   rl workstation egress my-box --totals --since 720h
   ```

3. Read the `SOURCE` column to see where each row's numbers came from. `edge` is what an Edge
   counted. `box` is what the workstation reported about itself, and is only a usage figure.

To read usage across workstations and users, with token amounts and cost, use
[`rl usage`](https://docs.ringleader.dev/reference/cli/commands/usage/).

## Next steps

- [`rl workstation egress [workstation]`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-workstation-egress-workstation)
  lists every flag, column and exit code of the command that reads records.
- [Workstation reach audit](https://docs.ringleader.dev/security/outbound/reach-audit/) turns
  the records of an `audit` workstation into a `strict` policy.
- [Edge management](https://docs.ringleader.dev/security/outbound/edge-management/) says how to declare the Edge that keeps the
  records.

