Skip to main content

Formula Metrics

Formula Metrics let you create your own fleet-wide insights from the metrics your devices already send, similar to Device Vitals. You define a Formula Metric with a formula that combines your metrics, and Memfault computes it for every device in your fleet.

A formula is a ratio: one metric divided by another, with optional scaling. You don't need to change any firmware or SDK configuration.

When to Use a Formula Metric​

Use a Formula Metric when the number you care about is the relationship between two metrics, rather than either metric on its own. Some common patterns:

  • Duty cycle: a *_ms duration metric divided by the total time it was measured over, such as CPU active time or radio-on time.
  • Error or drop rates: failed operations divided by attempted operations, such as failed flash writes over total writes.
  • Utilization: a used amount divided by a total capacity, such as current battery capacity over design capacity.
  • Achieved rates: a count divided by the time it took, such as sensor samples taken per second.

See Examples for complete configurations.

Defining a Formula Metric​

Formula Metrics are configured per project. To create one, go to Project Settings and open the Formula Metrics tab, then select New Formula Metric.

Create Formula Metric editor

Each Formula Metric has:

  • Name: shown on charts, device tiles, and in device search.
  • Description (optional): a short explanation for your team of what the metric measures.
  • Unit (optional): the label shown alongside values, for example % or hours. The unit is for display only. Memfault doesn't convert values to match it.
  • Formula: how the metric is calculated, described below.

You need write access to the project to create, edit, or delete a Formula Metric. Anyone with read access can view them.

Formula​

A formula consists of a scaled ratio between two metrics:

Offset ± Multiplier × ( (A × sum(numerator)) / (B × sum(denominator)) )
FieldDescription
NumeratorThe metric to divide. Its values are summed over the time period being measured.
DenominatorThe metric to divide by. Its values are also summed.
A, BCoefficients applied to the numerator and denominator. Use these for unit conversions.
MultiplierScales the ratio, for example 100 to express it as a percentage.
OffsetA constant added to (or subtracted from) the scaled ratio. Use 0 for a plain ratio.

For a plain percentage, set Offset to 0, Multiplier to 100, and both coefficients to 1.

Metric Requirements​

When you save a Formula Metric, Memfault checks that:

  1. Both metrics exist in the project.
  2. Both metrics are numeric (integer or float).
  3. Both metrics are reported in the same report type, for example both in heartbeat reports or both in the same session.

Metrics that don't meet these requirements are shown disabled in the metric lists. Once you pick the numerator, metrics from other report types are disabled in the denominator list. Hover over a disabled metric to see why.

Examples​

These examples use custom metrics that your firmware would define. Replace the metric names with your own.

Effective HID Report Rate​

The number of HID reports a device actually sends per second while it's streaming input. Compare it against your advertised polling rate (for example, 1000 Hz) to see whether devices in the field hold that rate, and how it changes across software versions. The 1000 coefficient on the numerator converts the denominator from milliseconds to seconds:

FieldValue
UnitHz
Offset0
Multiplier1
Numerator1000 × hid_tx_reports
Denominator1 × hid_streaming_time_ms

hid_streaming_time_ms should only count time when the device had new input to report, such as while a mouse is moving. Most HID devices skip a report when there's nothing new to send, so dividing by total connected time understates the achieved rate.

HID Report Delivery Rate​

The percentage of HID reports that were delivered, computed from the reports that were dropped. Subtracting from an Offset of 100 turns the drop rate into a delivery rate:

FieldValue
Unit%
Offset100, subtract
Multiplier100
Numerator1 × dropped_hid_reports
Denominator1 × hid_tx_reports

hid_tx_reports must count every report the device tried to send, including dropped ones. If it only counts successful reports, the result overstates the delivery rate.

File System Utilization​

The percentage of file system capacity in use:

FieldValue
Unit%
Offset0
Multiplier100
Numerator1 × fs_bytes_used
Denominator1 × fs_bytes_total

Because values are summed across reports, the result is the average utilization over the selected time range, not the latest reading. Report both metrics in every heartbeat so the sums line up.

Using Formula Metrics​

Dashboard Charts​

To chart a Formula Metric across your fleet, open a dashboard, select Create Chart, and choose Generic > Formula Metric Chart. Charts support three visualizations:

  • Summary: a single fleet-wide value, such as the median.
  • Percentiles: the distribution of values across devices.
  • Percentiles Over Time: how the distribution changes over the selected time range.

Like other charts, you can compare device sets or software versions, and select Drilldown to see the matching devices in device search.

New Formula Metric Chart editor

Device Tiles​

To see a Formula Metric's value for a single device, add a tile on the device details page. In the Device Vitals section, select Create Tile and choose the Formula Metric. You can set a threshold to highlight values above or below a limit.

Tiles read from heartbeat reports only. If the formula's metrics aren't reported in heartbeats, the tile shows Not collected.

New Formula Metric Tile editor

To find devices by a Formula Metric's value, add a Formula Metrics filter in the Device Inventory.

Editing and Deleting Formula Metrics​

You can edit a Formula Metric's name, description, unit, and formula at any time. Charts and tiles that use it pick up the new formula automatically.

You can't delete a Formula Metric while a dashboard chart or device tile uses it. Remove those charts and tiles first, then delete the Formula Metric.

Limitations​

  • Formula Metrics always sum the numerator and denominator values. Averages, minimums, and maximums aren't supported.
  • You can't divide a heartbeat metric by a session metric. See Metric Requirements.