# Metrics

Collect the metrics of the Backend and look up the most useful ones.

## Collect the metrics

The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) gives its metrics in the Prometheus text format at the path `/metrics` of the metrics port, `9090` by default. Each metric comes with a `# HELP` line that says what it counts and a `# TYPE` line, so the endpoint itself is the full list of the metrics of your version.

#### Variant: Kubernetes cluster

The chart makes the Service `<release>-metrics` with the port `9090`: a metrics collector in the cluster scrapes `http://<release>-metrics.<namespace>.svc:9090/metrics`. For the default release `platforma` in the namespace `platforma`, this is for example `http://platforma-metrics.platforma.svc:9090/metrics`. The chart does not let you move or stop this port: the probes of Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) use it.

To look at the metrics from your computer:

```sh
kubectl port-forward -n platforma svc/platforma-metrics 9090:9090
curl -s http://127.0.0.1:9090/metrics | grep '^pl_'
```

#### Variant: Single Server

The Backend serves the metrics on `127.0.0.1:9090` of the server, so only a collector on the same server can scrape them.

```sh
curl -s http://127.0.0.1:9090/metrics | grep '^pl_'
```

With TLS on the Backend (`--listen-tls`), the metrics port serves HTTPS only, with the same certificate as the API: use `https://` in the address of the collector.

The Backend also writes its metrics to files in `<main-root>/metrics` every 20 seconds and deletes the files after 48 hours: support can read them after a problem.

## Most useful metrics

The tables list the metrics that show the state of the service best, in groups. The list is for the most recent version of the Backend: an older version can lack some of them. The metrics endpoint lists all metrics of your version with their `# HELP` lines.

### Jobs and queues

| Metric                                     | Type    | Labels             | What it shows                                                                                                                                                                   |
| ------------------------------------------ | ------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pl_ctl_runner_runner_active_tasks_count`  | gauge   | `command_name`     | Jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) that run now, for each command                               |
| `pl_ctl_runner_runner_duration_seconds`    | gauge   | `command_name`     | Sum of the run time of the jobs that run now, for each command. A value that only grows shows a job that does not end                                                           |
| `pl_queue_compute_current_requests`        | gauge   | `controller`, `id` | Requests for CPU and memory that wait now in the job queues of the Backend. The jobs have `controller="ctl_runner"`; the work of a folder storage has `controller="data"`       |
| `pl_queue_compute_current_allocations`     | gauge   | `controller`, `id` | Requests for CPU and memory that have their resources now                                                                                                                       |
| `pl_ctl_workflow_execution_queue_added`    | counter |                    | Steps of workflows (The part of a Block that runs in the Backend. It starts the tools on the data and collects the results. Users do not edit it.) added to the execution queue |
| `pl_ctl_workflow_execution_queue_finished` | counter | `status`           | Steps of workflows that finished, by result                                                                                                                                     |
| `pl_queue_events_added_total`              | counter | `queue`            | Events added to an internal queue of the Backend                                                                                                                                |
| `pl_queue_events_processed_total`          | counter | `queue`            | Events that an internal queue finished. Added minus processed is the depth of the queue since the start of the Backend                                                          |

### Storage

These metrics cover the storages that are buckets (Amazon S3, Google Cloud Storage or an S3-compatible storage). The label `storage_id` names the storage; `direction` is `upload` or `download`.

| Metric                               | Type      | Labels                                       | What it shows                                                                                                                  |
| ------------------------------------ | --------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `pl_objfs_transfer_bytes_total`      | counter   | `store`, `storage_id`, `direction`           | Bytes of uploads and downloads                                                                                                 |
| `pl_objfs_transfers_total`           | counter   | `store`, `storage_id`, `direction`, `result` | Uploads and downloads that finished, by result                                                                                 |
| `pl_objfs_transfers_current`         | gauge     | `store`, `storage_id`, `direction`           | Uploads and downloads that run now                                                                                             |
| `pl_objfs_transfer_duration_seconds` | histogram | `store`, `storage_id`, `direction`           | Time of an upload or a download                                                                                                |
| `pl_objfs_part_retries_total`        | counter   | `store`, `storage_id`, `direction`, `reason` | Parts of a file that the Backend sent or read again, by reason. A fast growth shows a problem of the network or of the storage |
| `pl_objfs_calls_total`               | counter   | `store`, `storage_id`, `op`, `result`        | Calls to the storage, by operation and result                                                                                  |

### API

The `grpc_server_*` metrics count the requests of the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.) and pl-cli (The command-line client of Platforma. Administrators use it to manage users and projects on the Backend.) to the API. They have the label `server_name="external_grpc"`.

| Metric                         | Type      | Labels                                                  | What it shows                                                                                                                                                          |
| ------------------------------ | --------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `grpc_server_handled_total`    | counter   | `grpc_service`, `grpc_method`, `grpc_type`, `grpc_code` | Requests that ended, by method and status code. A growth of codes other than `OK` and `Canceled` shows errors                                                          |
| `grpc_server_handling_seconds` | histogram | `grpc_service`, `grpc_method`, `grpc_type`              | Time of a request                                                                                                                                                      |
| `grpc_server_started_total`    | counter   | `grpc_service`, `grpc_method`, `grpc_type`              | Requests that started                                                                                                                                                  |
| `pl_api_user_tx_seconds`       | histogram |                                                         | Time of a transaction of a client                                                                                                                                      |
| `pl_api_number_user_tx_total`  | counter   | `success`                                               | Transactions of clients, by result: `true`, `conflict`, `error`, `discarded` or `client_gone`. Many `conflict` show clients that change the same data at the same time |

### Database

The Backend keeps its database in RocksDB on the disk of the Backend.

| Metric                                         | Type    | Labels   | What it shows                                                                                                               |
| ---------------------------------------------- | ------- | -------- | --------------------------------------------------------------------------------------------------------------------------- |
| `pl_rocksdb_sst_current_bytes`                 | gauge   | `level`  | Size of the database files at each level. The sum over the levels is the size of the database on the disk                   |
| `pl_rocksdb_live_data_estimated_current_bytes` | gauge   |          | Estimated size of the live data. The size on the disk minus this value is the space that the background compaction can free |
| `pl_rocksdb_pending_compaction_current_bytes`  | gauge   |          | Bytes that the background compaction must still rewrite                                                                     |
| `pl_rocksdb_sst_files_current`                 | gauge   | `level`  | Number of database files at each level. Many files at level `0` can slow down the writes                                    |
| `core_rocksdb_ticker_total`                    | counter | `ticker` | The internal counters of RocksDB, for example `ticker="block.cache.miss"`                                                   |

### Process

The Prometheus client library of the Backend adds the standard metrics of a Go program.

| Metric                          | Type    | What it shows                                                      |
| ------------------------------- | ------- | ------------------------------------------------------------------ |
| `process_resident_memory_bytes` | gauge   | Memory of the Backend process                                      |
| `process_cpu_seconds_total`     | counter | CPU time of the Backend process                                    |
| `process_open_fds`              | gauge   | Open files and network connections of the Backend process          |
| `go_goroutines`                 | gauge   | Goroutines of the Backend. A value that only grows can show a leak |
| `go_memstats_heap_inuse_bytes`  | gauge   | Memory that the Go heap of the Backend uses                        |

The jobs run as separate processes or pods: these metrics do not include them.

## Next

- [Ports and endpoints](/reference-ports-and-endpoints/)
- [Get help](/maintain-get-help/)

Source: https://docs.platforma.bio/reference-metrics/
