Skip to content

Queries, formulas and variables

The five chart widgets (Time series, Query value, Top list, Table and Pie) are built from queries, optionally combined by formulas and narrowed by variables. The widget editor builds all of this for you. This page explains the rules behind it.

A widget has up to 10 queries, lettered a to j. Every query in a widget runs over the same window and bucket size.

FieldDescription
idA single letter, a to j. Unique in the widget.
sourcemonitors, incidents, rum, logs, metrics or traces.
measureA measure of the source. See data sources.
aggregationOptional. Must be one the measure allows. Without it, the measure’s default is used.
filtersZero or more filters, below.
group_byZero to two fields that support grouping.
metricThe metric name. Metrics source only. May be a variable such as $metric.
hiddenCompute the query but do not draw it. Use it for queries that only feed a formula.
aliasA label for the legend or column.

A filter is a field, an operator and values.

{ "field": "region", "op": "in", "values": ["us-east-1", "$region"] }
OperatorMeaning
in, not_inThe field equals, or does not equal, any of the values.
contains, not_containsThe field contains, or does not contain, the text.
gt, gte, lt, lteNumeric comparisons. These take one value.

Each field accepts only some operators. The catalog lists them. A filter has 1 to 50 values of up to 512 characters each.

Grouping splits a query into one series (or row) per value. Time series draw the top series_limit groups. Top list, Table and Pie show up to their limit rows.

You can group by one or two fields. A two-field group makes one series per combination.

A formula combines queries into a new series or value. Reference a query by its letter.

{ "id": "f1", "expr": "b / a * 100", "alias": "Failure rate", "unit": "percent" }

A widget has up to 5 formulas, f1 to f5, of up to 256 characters each. A formula can set alias, unit and hidden.

PartSyntax
Arithmetic+, -, *, /
GroupingParentheses
Numbers42, 0.5
Queriesa to j
FunctionWorks onDescription
abs(x)AnyAbsolute value.
log10(x)AnyBase-10 logarithm.
clamp_min(x, n)AnyRaises values below n up to n.
clamp_max(x, n)AnyLowers values above n down to n.
moving_avg(x, points)Time series onlyMoving average over points buckets.
timeshift(x, 1d)Time series onlyThe series from the given duration earlier, placed on the current window.
GoalExpression
Error percentage from two countsa / b * 100
Successful checksa - b
Never show a negativeclamp_min(a - b, 0)
Smooth a noisy seriesmoving_avg(a, 5)
Change against yesterdaya - timeshift(a, 1d)
  • Groups. Grouped queries join on identical group keys. A query without groups applies to every group.
  • Nulls. Division by zero gives a gap, and so does any null operand.
  • Window. Every query behind a formula uses the same window and bucket size.
  • Hidden queries. A hidden query is computed and available to formulas, but not drawn.

A variable is a named dropdown for the whole dashboard. Define variables in Settings while editing. They appear in the variables bar.

{
"name": "region",
"label": "Region",
"source": "monitors",
"field": "region",
"multi": true,
"include_all": true,
"default": ["*"]
}
FieldDescription
nameLowercase letters, digits and _, starting with a letter, up to 32 characters. Used as $name.
labelOptional display name.
sourceThe source whose field supplies the values.
fieldA field of that source that supports variables. See the Variable column in data sources.
metricFor metric tag variables only. Scopes the values to one metric.
multiAllow several selections.
include_allOffer All.
defaultThe starting selection. ["*"] is All.
valuesOptional fixed list, used instead of values from your data.

A dashboard has up to 20 variables.

Use $name as a filter value, or as the metric of a metrics query.

{ "field": "region", "op": "in", "values": ["$region"] }
  • A value is either a literal or exactly $name. You cannot mix them in one value, so prod-$env is not allowed. A filter can still hold several values, such as ["us-east-1", "$region"].
  • With several values selected, the variable expands to all of them.
  • With All selected, the variable’s value is dropped. A filter left with no values is removed, so the widget is not filtered by that field.
  • Entity widgets such as Monitor grid and Incidents take the same filters, so variables work there too.

The dropdown loads its values from your data and searches as you type. A variable with a fixed values list uses that list instead.

The current selection is stored in the URL as var-<name>=a,b, for example var-region=us-east-1,eu-west-1. Open the link and the same selection applies. Hover a variable to highlight the widgets that use it.

A selection in the URL does not edit the dashboard. To change the starting selection, edit the variable’s default in Settings.

Template variables default to All, except $monitor and $app. Those default to your first monitor or first RUM application when you create the dashboard from the template.