# dflow db:metrics

> Read CPU, memory, and network usage metrics and metered integrals for one managed database.

Web page: /docs/cli/data/db-metrics/

This reads CPU, memory, network receive, and network transmit metrics for one managed database service through the API, along with allocated capacity (including `storage_bytes`), observed pods, coverage status, and deterministic metered totals (`core_seconds`, `byte_seconds`, `bytes`).

```bash
dflow db:metrics SVC [--range 1h] [--from RFC3339 --to RFC3339] [--step 60s] [--metrics cpu,memory,network_rx,network_tx] [--pods POD] [--group-by service|pod] [--summary-only]
```

## Flags

`--range` picks a preset window (`15m`, `1h`, `6h`, `24h`, `7d`, `30d`). Default is `1h`. `--from` and `--to` pass an explicit UTC half-open window `[from, to)` (RFC3339, whole seconds) and cannot be combined with `--range`. A bucket counts toward the window that contains its start time, so adjacent windows never count the same bucket twice; an unaligned window leaves out its partial edge buckets. `--step` picks a fixed bucket size (`60s`, `300s`, `900s`, `3600s`, `14400s`, `86400s`; max 744 buckets). `--metrics` selects a comma-separated subset of `cpu`, `memory`, `network_rx`, `network_tx`. `--pods` limits results to one or more pod names (at most 100). `--group-by` accepts `service` (default) or `pod`. `--summary-only` omits series points (`include_series=false`). Pass `--output json` for the full JSON document.

## What you see

Text mode prints the window, coverage, observed pods, an `allocated:` line (CPU, memory, replicas, and storage), and a summary table (`METRIC`, `LATEST`, `AVG`, `PEAK`, `METERED TOTAL`, `ALLOCATED`). A window with no samples still exits 0: the header shows `coverage=empty (0/N)`, and every value cell is `-`. Missing buckets in JSON are `null`, never `0`.

## When it fails

Exit 1 is validation. Exit 2 is auth. Exit 3 means the database service was not found. Exit 6 is precondition (`metrics_sink_not_configured` when the API has no metrics query source configured). Exit 10 means the API could not be reached.
