Skip to main content

Nola Query Language (NolaQL)

NolaQL is an expression language for querying data from the Nola dashboard.

It enables you to take data from metrics, compare metrics to each other and run calculations and analysis on them.

It is used as part of writing conditions for Notifications.

Syntax

The language supports some basic and familiar syntax:

  • 1 + 1
  • max($a) >= min($b)
  • false || true

Metrics

Querying metrics from Nola involves referencing the metric by its name, and optionally specifying a time range, time bucket and subslice:

$metric_name{time_range,time_bucket}[subslice]
FieldDescriptionExamples
$metric_nameThe name of the metric to query. It always begins with a $ and is based upon the metric's name in the Nola dashboard, with invalid characters replaced by _.$occupancy, $band_room_staff_count
time_rangeCounting back from the current time, how long of a time range to fetch data for. It is composed of a number and a unit. The default value is 10m. (Required)5m, 1h30m, 1d
time_bucketThe size of each time bucket for the metric. Each value in the metric data will represent this time interval. The default value is OneMinute. (Required)OneMinute, TenMinute, Hour, Day
subsliceSelect a subslice of the metric data. This is useful for picking out certain times within the selected time range. (Optional)[-1] (last value), [0:5] (first 5 values)

Available Functions

FunctionDescriptionExample
max($metric) -> numberReturns the maximum value of the metric as a number.max($metric{5m,OneMinute})
min($metric) -> numberReturns the minimum value of the metric as a number.min($metric{5m,OneMinute})
mean($metric) -> numberReturns the mean (average) value of the metric as a number.mean($metric{5m,OneMinute})
median($metric) -> numberReturns the median value of the metric as a number.median($metric{5m,OneMinute})
mode($metric) -> numberReturns the mode value of the metric as a number.mode($metric{5m,OneMinute})
first($metric) -> numberReturns the first value of the metric as a number. This is the same as using a [0] subslice.first($metric{5m,OneMinute})
last($metric) -> numberReturns the last value of the metric as a number. This is the same as using a [-1] subslice.last($metric{5m,OneMinute})
rate($metric) -> $metricReturns a metric (of 1 less length) that represents the rate of change (per second) of the input metric.rate($metric{5m,OneMinute})
increase($metric) -> $metricReturns a metric (of 1 less length) that represents the increase (from the previous value) of the input metric.increase($metric{5m,OneMinute})
holt_winters($metric, projection_duration, season_length, alpha, beta, gamma) -> $metricPerforms a Holt-Winters forecast on the input metric.
  • projection_duration must be a duration in whole minutes (e.g. 5m).
  • season_length must be a whole integer. It is recommended to have at least 2 seasons of previous data.
  • alpha, beta and gamma are smoothing parameters and default to 0.4 if omitted.

This is the recommended forecasting method.

holt_winters($metric{20m,OneMinute}, 5m, 10)

This would project $metric 5 minutes into the future, using a season length of 10 minutes (10 * OneMinute) and default smoothing parameters.
linear_predict($metric, projection_duration) -> $metricPerforms a forecast using linear regression on the input metric.
  • projection_duration must be a duration in whole minutes (e.g. 5m).
linear_predict($metric{10m,OneMinute}, 5m)
ema_predict($metric, alpha, projection_duration) -> $metricPerforms a forecast using Exponential Moving Average on the input metric.
  • alpha is the smoothing parameter
  • projection_duration must be a duration in whole minutes (e.g. 5m).
ema_predict($metric{10m,OneMinute}, 0.4, 5m)
even_distribution(
[$metric, ...],
["Metric Label", ...],
projection_interval,
min_metric_value,
diff_threshold) -> boolean

Compares a list of metrics and performs pair-wise checks to see if they are evenly distributed.

Metric A in the pair-wise comparison between A and B is considered unevenly distributed if:

  • A's last value is greater than min_metric_value and
  • The difference in the projected value after projection_interval for both metrics is more than diff_threshold. This function uses Holt-Winters projection.

$metrics and metric_labels must be the same length.

even_distribution([$metric_a{10m, OneMinute}, $metric_b{10m, OneMinute}], ["Metric A", "Metric B"], 5m, 30, 25)

This would check that every pair of metrics (A and B in this instance) are within 25 of each other.

Metrics under 30 are not checked against other metrics, but metrics greater than 30 will be evaluated against metrics under 30.

pt_arrival("Stop ID") -> booleanReturns true for 60 seconds from the moment when public transport arrives at a specified stop ID.pt_arrival("20016")
network_check("no_reply_in_seconds") -> booleanReturns true if at least one of the connected CCTV devices does not provide video stream. Nola checks camera status every 20 seconds, parameter no_reply_in_seconds specifies the minimum time when camera is not respondingnetwork_check("60")