# Metrics in the CLI

The `diagrid metrics` commands print the metrics behind the Dapr Ops Dashboard charts in your terminal. Use them to check a cluster while you debug it, or to give a script or an AI assistant the numbers without screenshots.

## Prerequisites

- The [Diagrid CLI](https://docs.diagrid.io/references/conductor/conductor-cli-intro#installing-the-cli), logged in with `diagrid login`
- The CLI set to Dapr Ops Dashboard with `diagrid product use conductor`, and the organization that owns the cluster selected with `diagrid org use`
- A connected cluster. Find its ID with `diagrid clusters list`.

## Cluster metrics

```bash
diagrid metrics cluster <cluster-id>
```

This shows the Dapr control plane, the Dapr scheduler's storage, the Diagrid agent, and the advisories firing on the cluster:

```
METRIC                          SERIES                       UNIT       LATEST      MIN        MAX
dapr_control_plane_uptime       app=dapr-sentry              seconds    1h27m23s
dapr_sentry_root_cert_expiry    -                            seconds    371d22h
dapr_scheduler_status           app=dapr-scheduler-server    value      1
dapr_control_plane_mem_usage    app=dapr-operator            bytes      21.0MiB     14.3MiB    22.8MiB
scheduler_etcd_quota_usage      -                            percent    0.0%        0.0%       0.0%
agent_pods_mem_usage            pod=diagrid-agent-otel-0     bytes      51.9MiB     37.3MiB    51.9MiB
```

The Dapr scheduler stores jobs and actor reminders in an embedded etcd database. To check its size and health over the last day:

```bash
diagrid metrics cluster <cluster-id> -m sched1,sched2,sched3,sched4,sched5 --since 24h
```

## Application metrics

```bash
diagrid metrics app <cluster-id> <app-id> --namespace <namespace>
```

This shows HTTP and gRPC traffic between the application and its Dapr sidecar in both directions, CPU and memory for the application and the sidecar, container restarts and crash loops, and Dapr error codes:

```
METRIC                          SERIES                     UNIT            LATEST     MIN        MAX
dapr_to_app_http_latency_95p    method=POST,path=/order    milliseconds    5.3ms      4.5ms      5.8ms
dapr_to_app_http_rps            method=POST,path=/order    rps             0.379      0.321      0.417
app_container_restart_count     -                          count           1
```

`--namespace` defaults to `default`.

## Read the output

Each row is one series of one metric. SERIES holds the labels that tell a metric's series apart, such as the control plane service or the HTTP path.

Metrics come in two kinds:

- **Point-in-time** metrics, such as uptime, status, certificate expiry, and restart counts, are read once at the current time. They have LATEST only, and `--since` does not change them.
- **Range** metrics, such as CPU, memory, latency, request rate, and error rate, are sampled across the time window. LATEST is the last sample, and MIN and MAX are the lowest and highest samples.

Each sample of a rate or latency metric covers the five minutes before it, so a spike shorter than a few minutes shows up lower in MAX than its true peak.

`no data` means the cluster sent nothing for that metric during the window. If almost every row says `no data`, the agent is probably offline: `diagrid clusters get <cluster-id>` shows when it last connected.

## Options

| Flag | Default | Description |
| --- | --- | --- |
| `--since` | `1h` | How far back to look, up to `720h` (30 days). |
| `--step` | chosen from `--since` | Time between samples, from `5s` to `2h`. |
| `-m`, `--metric` | a default set | Metric shortcodes to show, comma separated. |
| `--all` | | Show every metric available for the cluster or application. |
| `-o`, `--output` | `table` | `table`, `json`, or `yaml`. JSON and YAML contain the same rows as the table. |
| `--raw` | | Print every sample, in the API's response format. |

Run `diagrid metrics cluster --help` or `diagrid metrics app --help` for the full list of shortcodes. Some metrics need a minimum Dapr version and are left out on clusters running an older one.
