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
| Property | Type | Description |
|---|---|---|
| filters | FilterMetricConfig | Restricts which metrics users can select. |
| defaultValue | ValueMetricConfig | The 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.
| Filter | Type | Description |
|---|---|---|
| valueTypes | string[] | Only metrics whose type has one of these value types, e.g. Numeric. |
| types | string[] | Only metrics of these metric types, by the id of the metric type. |
| groups | string[] | Only metrics in these groups, by the id of the group. |
| static | boolean | Only static metrics (true), or only metrics with changing values (false). |
| hasValue | boolean | Only 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:
{
"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:
{
"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.