TICKscript uses lambda expressions to define transformations on data points as well as define boolean conditions that act as filters.
TICKscript tries to be similar to InfluxQL in that most expressions that you would use in an InfluxQL
WHERE clause will work as expressions
There are few exceptions:
- All field or tag identifiers must be double quoted.
- The comparison operator for equality is
All expressions in TICKscript begin with the
.where(lambda: "host" == 'server001.example.com')
These lambda expressions are stateful, meaning that each time they are evaluated internal state can change and will persist until the next evaluation.
This may seem odd as part of an expression language but it has a powerful use case.
You can define a function within the language that is essentially a online/streaming algorithm and with each call the function state is updated.
For example the built-in function
sigma that calculates a running mean and standard deviation and returns the number of standard deviations the current data point is away from the mean.
sigma("value") > 3
Each time that the expression is evaluated the new value it updates the running statistics and then returns the deviation.
This simple expression evaluates to
false while the stream of data points it has received remains within
3 standard deviations of the running mean.
As soon as a value is processed that is more than 3 standard deviation it evaluates to
Now you can use that expression inside of a TICKscript to define powerful alerts.
TICKscript with lambda expression:
stream .alert() // use an expression to define when an alert should go critical. .crit(lambda: sigma("value") > 3)
Converts a string into a boolean via Go’s strconv.ParseBool
bool(value string) bool
Converts a string or float64 into an int64 via Go’s strconv.ParseInt or simple
Strings are assumed to be decimal numbers.
int(value float64 or string) int64
Converts a string or int64 into an float64 via Go’s strconv.ParseFloat or simple
float(value int64 or string) float64
Computes the number of standard deviations a given value is away from the running mean. Each time the expression is evaluated the running mean and standard deviation are updated.
sigma(value float64) float64
Count takes no arguments but returns the number of times the expression has been evaluated.
The following mathematical functions are available. Each function is implemented via the equivalent Go function. Short descriptions are provided here but see the Go docs for more details.
|abs||Abs returns the absolute value of x.|
|acos||Acos returns the arccosine, in radians, of x.|
|acosh||Acosh returns the inverse hyperbolic cosine of x.|
|asin||Asin returns the arcsine, in radians, of x.|
|asinh||Asinh returns the inverse hyperbolic sine of x.|
|atan||Atan returns the arctangent, in radians, of x.|
|atan2||Atan2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.|
|atanh||Atanh returns the inverse hyperbolic tangent of x.|
|cbrt||Cbrt returns the cube root of x.|
|ceil||Ceil returns the least integer value greater than or equal to x.|
|cos||Cos returns the cosine of the radian argument x.|
|cosh||Cosh returns the hyperbolic cosine of x.|
|erf||Erf returns the error function of x.|
|erfc||Erfc returns the complementary error function of x.|
|exp||Exp returns e**x, the base-e exponential of x.|
|exp2||Exp2 returns 2**x, the base-2 exponential of x.|
|expm1||Expm1 returns e**x - 1, the base-e exponential of x minus 1.|
It is more accurate than Exp(x) - 1 when x is near zero. | | floor | Floor returns the greatest integer value less than or equal to x. | | gamma | Gamma returns the Gamma function of x. | | hypot | Hypot returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow. | | j0 | J0 returns the order-zero Bessel function of the first kind. | | j1 | J1 returns the order-one Bessel function of the first kind. | | jn | Jn returns the order-n Bessel function of the first kind. | | log | Log returns the natural logarithm of x. | | log10 | Log10 returns the decimal logarithm of x. | | log1p | Log1p returns the natural logarithm of 1 plus its argument x. It is more accurate than Log(1 + x) when x is near zero. | | log2 | Log2 returns the binary logarithm of x. | | logb | Logb returns the binary exponent of x. | | max | Max returns the larger of x or y. | | min | Min returns the smaller of x or y. | | mod | Mod returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x. | | pow | Pow returns xy, the base-x exponential of y. | | pow10 | Pow10 returns 10e, the base-10 exponential of e. | | sin | Sin returns the sine of the radian argument x. | | sinh | Sinh returns the hyperbolic sine of x. | | sqrt | Sqrt returns the square root of x. | | tan | Tan returns the tangent of the radian argument x. | | tanh | Tanh returns the hyperbolic tangent of x. | | trunc | Trunc returns the integer value of x. | | y0 | Y0 returns the order-zero Bessel function of the second kind. | | y1 | Y1 returns the order-one Bessel function of the second kind. | | yn | Yn returns the order-n Bessel function of the second kind. |