Reference to the last() function

Summary

last([<timeWindow>,] <tsExpression>)

Fills in gaps in each time series described by tsExpression, by inserting data points that have the last known value of the time series.

  • If you don’t specify timeWindow, fills gaps with duration of up to the metrics obsolescence period are completely filled. (depending on when data started flowing) with the last known value.
  • If you specify timeWindow, fills any gap you specify with the last know value.

See Caveats below for some limitations to this function.

Parameters

ParameterDescription
timeWindow Maximum amount of time to fill with inserted data points. If you omit this parameter, gaps with duration of up to the metrics obsolescence period are completely filled.
You can specify a time measurement based on the clock or calendar (1s, 1m, 1h, 1d, 1w), the window length (1vw) of the chart, or the bucket size (1bw) of the chart. Default is minutes if the unit is not specified.
tsExpression Expression that describes the time series in which to replace data gaps with the last value.

Description

The last() function allows you to assign the last known reported data point value to a gap of missing data. When you add last() to a tsExpression, a solid straight line with the value of the last reported data point will be drawn in place of gaps of missing data.

By default, last() applies the last reported data value to gaps of missing data with duration of up to the metrics obsolescence period. If you’d like this window to be smaller, you can use the timeWindow parameter. If you use last() with a function that uses interpolation, we apply last() to the last 15% of a chart window.

Examples

In the following example, we’ve zoomed in on ~sample.cpu.loadavg.1m and see missing data.

ts_last before

We decide to replace the missing data with the last value before the gap. What that is differs for different missing data windows.

ts_last

Then we replace the missing data with the first good value after the gap using next.

ts next

Caveats

The function returns results only if:

For example, if you specify last(1vw, ts(my_query), and if your view window is greater than 4w (the metrics obsolescence period if the default configuration is not changed), the query fails with an error.

See Also

Using Moving and Tumbling Windows to Highlight trends

Other missing data functions include