Skip to main content

Metric Field

type: "metric"

A select of the metrics provided by the installed plugins. Besides the metric, users can select a unit to convert the value to, and whether the widget receives the current, minimum, maximum or average value. See In-depth: Metrics.

Additional Properties

PropertyTypeDescription
filtersFilterMetricConfigRestricts which metrics users can select.
defaultValueValueMetricConfigThe metric selected by default.

Filters

Use filters to only offer metrics your widget can display. For example, a gauge can only display numeric values, so it shouldn't offer text metrics.

FilterTypeDescription
valueTypesstring[]Only metrics whose type has one of these value types, e.g. Numeric.
typesstring[]Only metrics of these metric types, by the id of the metric type.
groupsstring[]Only metrics in these groups, by the id of the group.
staticbooleanOnly static metrics (true), or only metrics with changing values (false).
hasValuebooleanOnly metrics that currently have a value.

If a selected metric doesn't match the valueTypes or types filters, e.g. after a dashboard was imported, the metric hooks throw an error.

Example

A metric field offering only numeric metrics:

mobro-widget-config.json
{
"config": [
{
"name": "metric",
"label": "Metric",
"type": "metric",
"filters": {
"valueTypes": ["Numeric", "Duration", "Currency"]
}
}
]
}

A metric field with a metric selected by default, taken from the Media Controls widget pack:

mobro-widget-config.json
{
"config": [
{
"name": "volume_metric",
"label": "Volume metric",
"type": "metric",
"filters": {
"valueTypes": ["Numeric"]
},
"defaultValue": {
"id": "modbros_media.m_mvol",
"plugin": "modbros_media",
"categories": ["media"]
}
}
]
}

Usage

To read the value of this field in a widget, use useMetricField or useMemoizedMetricField.