Reference to the rawif() function

Summary

rawif(<condition-tsExpression>, <then-tsExpression>, [<else-tsExpression>])

Returns the points from then-tsExpression while condition-tsExpression returns non-zero values. Returns points from else-tsExpression otherwise. The results are computed from real reported data values only. Use if() to include interpolated values.

Parameters

ParameterDescription
condition-tsExpression Expression that describes the time series to be used as the condition. For example, if the condition is cpu.loadavg.1m>100, then the condition evaluates to true if the load is greater than 100, and to false otherwise.
This expression typically uses a comparison operator.
then-tsExpression Required expression that describes the time series to return when the condition is met.
  • If condition-tsExpression is true for a point, we return the corresponding point from then-tsExpression.
  • If condition-tsExpression is false for a point, we return nothing for that point.
else-tsExpression Optional expression that describes the time series to return when the condition is not met.
If you include else-tsExpression:
  • If condition-tsExpression is true for a point, we return the corresponding point from then-tsExpression, that is, we ignore else-tsExpression
  • If condition-tsExpression is false for a point, we return the corresponding point from else-tsExpression. That means we return return a continuous stream of points that change depending on the value of the condition.

Description

The rawif() conditional function returns data values based on the specified condition. The results are computed from real reported data values only with no interpolation. You can determine what values are returned if the condition is true, and what values are returned if the condition is false. The query engine treats a 0 value as false, and all other values as true.

Each of the tsExpressions can be a constant or a query that returns one or more non-constant time series.

Examples

The following example set (ts(~sample.requests.latency AND source="app-2*")) starts with a simple metric, and the chart looks like this:

rawif metric

Now we use an rawif condition that returns a value of 50 for any point that’s greater than 100, and a value of 25 otherwise: rawif(ts(~sample.requests.latency AND source="app-2*")>100, 50, 25):

rawif then else

Finally, we look at an example that does not use an else-tsExpression. For this case, we’ve limited the query to one time series: rawif(ts(~sample.requests.latency AND source="app-20")>200, 0):

rawif then