---
title: Metrics
description: What a metric is, how it summarizes one session with a number, and where to publish, view, and manage metrics.
sidebar:
  order: 19
---
## Overview

A **metric** is a named numeric value that summarizes one [session](/docs/learn/sessions), such as the top speed of a drone flight, the distance of a vehicle drive, or the peak CPU usage during a robot run. A session holds at most one value for each defined metric.

Topic data records what a robot did moment by moment, whereas a metric records one value for a whole activity. When you publish the same metrics for each session, you can track how your fleet performs over time, find the robot runs whose values stand out, and examine the sessions behind those values.

## Choosing and defining metrics

Start by choosing the indicators that matter for your robot runs: measurements of how a device performed during one run, such as the distance it covered or the number of faults it recorded. Good candidates are values worth comparing across many runs, because Roboto aggregates them by device, by period, such as a quarter, and by the properties of their sessions, such as a firmware version stored in a [custom field](/docs/learn/concepts#custom-fields-section).

Each indicator becomes a **metric definition**: a name that is unique in your organization, with an optional unit and description. A name may use ASCII letters, digits, and the characters `-`, `.`, `_`, and `~`. Group related metrics by concern, with dots between the parts of a name. For example, counts of fault events can be three definitions: `fault_event.collisions`, `fault_event.planning_failures`, and `fault_event.estops`.

You can create a definition with `MetricDefinition.create`, or let Roboto create one, without a unit or description, the first time you publish a value under a new name.

## Publishing values

Once your metrics are defined, you publish a value of each metric for each session. A value may already exist in a file or in the session's metadata, or you can compute it from the session's topic data or from a device's [configurations](/docs/learn/concepts#configurations-section).

You publish values with the SDK. An [action](/docs/learn/actions) that runs on each new session can publish the same metrics for every robot run. The SDK has the following methods:

- `Session.publish_metrics` publishes values for a `Session` object that you already have, such as one that `Session.from_id` or `Session.create` returns.
- `Metric.publish` publishes values for a session by its ID, without a `Session` object, such as `Metric.publish(session_id="se_abc123", metrics=[...])`.

The following example publishes two values for a session:

```python
from roboto import Session
from roboto.domain.metrics import MetricEntry

# Replace se_abc123 with the ID of your session.
session = Session.from_id("se_abc123")
session.publish_metrics(
    [
        MetricEntry(name="speed.max_mps", value=12.4),
        MetricEntry(name="battery.min_voltage", value=21.8),
    ]
)
```

## Properties of a value

Each value records the following:

- **Session.** The session that the value summarizes. A new value for the same metric and session replaces the old one. If you reprocess a robot run, publish its metrics again to update them.
- **Device.** The [device](/docs/learn/devices) that produced the value, or none. By default, Roboto records the device attached to the session.
- **Invocation.** The ID of the action invocation that published the value, if an action published it.
- **Publication.** When the value was published and who published it.

Roboto places each value in time by its session's start or end time, so a chart of a metric shows when each robot run took place, not when its value was published.

## Viewing metrics

In the web app, you can view metrics in three places:

- **The Metrics page.** In the navigation menu, click **Metrics**. The page shows a dashboard, which arranges cards in sections. A trend card shows one metric's value for the current period and its change since the previous period. A chart card plots a metric's values individually or by period. A period combines the values of the sessions in it as a sum, mean, maximum, minimum, or count. You can filter the data, change the time range and the period, and save a dashboard for yourself or share it with your organization.
- **A device's Metrics tab.** The tab shows the same dashboards, restricted to the values from that device.
- **A session's Metrics tab.** The tab lists every metric of the session, grouped by the parts of each metric's name, so that `imu.accel.x` sits under `imu` and then `accel`. Click a metric to see its details.

With the SDK, `Metric.get_by_session` lists a session's values, `Metric.query` returns the values of one metric over a time range, and `Metric.aggregate` combines them by day, week, month, quarter, or year.

To find sessions by the value of a metric, write `metric.` and the metric's name in a [RoboQL](/docs/roboql/overview) query on sessions, such as `metric.speed.max_mps > 10`.

## Managing metrics

To change a definition's unit or description, use the **Metric Definitions** tab of the **Metrics** page, or `MetricDefinition.update`. The tab appears when you can edit your organization's metric definitions.

To delete a definition and every value recorded under it, use `MetricDefinition.delete`. You can't undo a deletion.

For every method and argument, see the [metrics SDK reference](/docs/reference/python-sdk/roboto/domain/metrics).
