Writing Expressions for KloudMate Alarms
10 min
alarm expressions allow you to manipulate query results using math and other operations kloudmate alarms can only target numeric data if a query returns time series data, it must be reduced using expressions before it can be used as an alarm target each query or expression is represented by a unique alphabetical notation (a, b, c, and so on) while writing an expression, one or more queries or other expressions can be passed as parameters using their notation expression operations expression operations kloudmate supports three types of operations in alarm expressions math expression reduce condition expression math expression math expression takes time series or number data returned by a query or an expression and turns them into different time series and numbers using mathematical operations or functions input any mathematical operation to apply to the data returned from other queries or expressions queries and expressions are passed as parameters using their alphabetical notation prefixed with a dollar sign, for example, $a mathematical operations arithmetic operations ++ (increment) (decrement) + (addition) (subtraction) (multiplication) / (division) % (modulo) ^ (exponentiation) examples ++$a , $a++ , $a+1 , $a 2 , $a 2 , $a/6 , $a%$b , $a^2 boolean operations \== (equal to) != (not equal to) < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) examples $a==0 , !$a!=0 , $a<$b , $a>10 , $a<=$d , $a>=$d logical operations && (and) || (or) ifnull (if nodata) examples $a && $d , $a and $d , $a or $d , $a || $d , ifnull($a, 0) for the above operations when both $a and $b are numbers, the operation is performed between the two numbers if one parameter is a number and the other is a time series, the operation is performed between the number and each value in the time series individually if both $a and $b are time series data, the operation is performed between each value in the two series having the same timestamps boolean and logical operations return 0 for false and 1 for true using expressions for multiple query conditions when working with multiple queries in a single alarm use the reduce function for all time series outputs (e g , mean, max, last) use the ifnull logic with all reduced values so that if any query returns nodata, it does not affect the evaluation of other queries example ifnull($a, 0) > 50 || ifnull($b, 0) > 90 ifnull — checks for nodata and assigns the given value (0) to that node if true > — arithmetic operation that checks the condition || — logical or operation that evaluates both query nodes mathematical functions abs — returns the absolute value e g , abs( 1) or abs($a) log — returns the natural logarithm returns nan if the value is less than 0 e g , log( 1) or log($a) round — returns a rounded integer value e g , round(3 123) or round($a) ceil — rounds up to the nearest integer e g , ceil(3 123) returns 4 floor — rounds down to the nearest integer e g , floor(3 123) returns 3 built in time range variables to get queried data in a data per time range format (e g , data/min), divide the data by the appropriate time range variable the following four built in variables are available $range\ m — time range in minutes $range\ s — time range in seconds $range\ h — time range in hours $range\ d — time range in days reduce reduce takes one or more time series or numbers of data returned from a query or an expression and turns them into a single number inputs reduction function select the function to apply — mean() , max() , min() , sum() , last() , or count() input select the query or expression to reduce using its alphabetical notation the selected reduction function aggregates the values of the query or expression into a single value reduction functions mean() — average value max() — maximum value min() — minimum value sum() — sum of all values last() — last value count() — total number of values condition expression condition expression takes one or more time series or numbers of data returned from queries or expressions and gives a boolean value as a result — 0 (false) if the condition is not met, or 1 (true) if it is met inputs when select the reduction function — last() , mean() , max() , min() , sum() , or count() of select the query or expression using its alphabetical notation (e g , a, c) condition string select the comparison condition — is above , is same or above , is below , or is same or below threshold enter the numeric value to evaluate the condition against the selected reduction function is applied to the selected query or expression to generate a single value this value is then compared against the provided threshold according to the selected condition when the input is a collection of time series or number data, the reduction function is applied to each element individually each reduced output is evaluated against the condition individually, and the outputs are then combined using the and operation you can add multiple conditions in a condition expression using the add condition button and choose how they work together using and or or logical operators nodes nodes represent individual queries or expressions used in the creation of alarms and dashboards each node is assigned an alphabetical identifier by default (e g , a, b, c), based on the order in which it was created nodes serve as a reference point, allowing users to easily identify and evaluate specific queries or expressions during data analysis while the default alphabetical naming is applied automatically, users have the flexibility to rename nodes for better clarity and easier identification if the custom node name includes spaces, it must be enclosed in ${} example ${cpu usage} related resources https //docs kloudmate com/understanding kloudmate alarms https //docs kloudmate com/setting up kloudmate alarms