# Metrics

The Collaboration Server On-Premises application and the Collaboration Worker can serve metrics in the Prometheus text format. Use them to scale the containers that run the [Coauthor sessions](limits-and-scaling.md).

<a id="why-these-metrics-are-only-for-coauthor"></a>

## Why these metrics are only for Coauthor

Each Coauthor session keeps an editor open in a container, and each container has a fixed number of slots for them. CPU and memory do not show how many slots are free. These metrics do, so you can add containers before new sessions fail.

The rest of the server keeps no such slots. To watch it, use the [request logs](request-summary.md) and the [resource use](resources.md) of your containers.

<a id="turn-on-the-endpoint"></a>

## Turn on the endpoint

* Set `ENABLE_METRICS_ENDPOINT=true` to turn on the endpoint. It is off by default.
* The endpoint is `GET /metrics` on port `8099`. Use `METRICS_HTTP_PORT` to change the port. This port has no other route.
* The port has no authentication. Do not publish it outside of your private network.

See the [application variables](installation/configuration/environmental-variables.md) and the [Collaboration Worker variables](installation/configuration/worker.md).

<a id="what-the-endpoint-serves"></a>

## What the endpoint serves

The endpoint serves only these metrics:

| Metric                                      | Type    | Labels                                         | Value                                                                              |
| ------------------------------------------- | ------- | ---------------------------------------------- | ---------------------------------------------------------------------------------- |
| `cs_keep_alive_editors_open`                | gauge   | `mode`: `rtc`, `detached`                      | Sessions that have a kept editor now.                                              |
| `cs_keep_alive_editors_max_open`            | gauge   | none                                           | Session slots of this container: the value of `KEEP_ALIVE_EDITORS_MAX_OPEN_PAGES`. |
| `cs_keep_alive_editor_route_requests_total` | counter | `mode`: `rtc`, `detached`; `result`: see below | Requests to sessions, by what the caller got.                                      |

The counter counts requests, not sessions. One session makes several requests.

What each container serves:

* The application with the built-in Collaboration Worker (`USE_BUILT_IN_COLLABORATION_WORKER=true`): the 2 gauges and the counter.
* The application with a separate Collaboration Worker (`USE_BUILT_IN_COLLABORATION_WORKER=false`): only the counter. The application sends the requests to the workers.
* The Collaboration Worker: only the 2 gauges.

The values of `result`:

* `success`: a session ran the request, or closed the session.
* `delayed`: `rtc` only. No slot was free. The request ran without a kept editor and was slower.
* `rejected`: `detached` only. No slot was free for a new session. The request failed with HTTP 503.
* `not_found`: `detached` only. The session lost its editor, for example because the container that kept it stopped or is being removed. The request failed with HTTP 404. In normal operation this value does not grow.
* `conflict`: `detached` only. The session is already open. The request failed with HTTP 409.

`result` tells where the request went, not if the script succeeded. A later release can add `result` values. For an error ratio, use `result!="success"`.

<a id="scale"></a>

## Scale

To scale, use the utilization over all containers that run sessions, and add containers above a target of about 70%:

```
sum(cs_keep_alive_editors_open) / sum(cs_keep_alive_editors_max_open)
```

Also watch the memory of each container. See [Monitoring resources](resources.md) and [the limits of a container](limits-and-scaling.md#limits).

<a id="alert"></a>

## Alert

To alert, use the requests that were slower or failed:

```
sum(increase(cs_keep_alive_editor_route_requests_total{result=~"delayed|rejected"}[5m])) > 0
```

It means that users got slower requests or HTTP 503: add containers now. Do not use it as the input of an autoscaler: it is 0 when you have the right number of containers, and also when you have too many.

To find out why a container was full, see the [log lines](limits-and-scaling.md#log-lines).

---

Full index of the Cloud Services documentation: [llms.txt](../../../llms.txt)
