|
1 | 1 | --- |
2 | 2 | id: alert_threshold_expr |
3 | | -title: Threshold trigger expression |
4 | | -sidebar_label: Threshold trigger expression |
| 3 | +title: Threshold Trigger Expression |
| 4 | +sidebar_label: Threshold Trigger Expression |
5 | 5 | --- |
6 | 6 |
|
7 | | -> When we configure the threshold alarm, we need to configure the threshold trigger expression. The system calculates whether to trigger the alarm according to the expression and the monitoring index value. Here is a detailed introduction to the use of the expression. |
8 | | -
|
9 | | -#### Operators supported by expressions |
10 | | - |
11 | | -``` |
12 | | -equals(str1,str2) |
13 | | -== |
14 | | -< |
15 | | -<= |
16 | | -> |
17 | | ->= |
18 | | -!= |
19 | | -( ) |
20 | | -+ |
21 | | -- |
22 | | -&& |
23 | | -|| |
24 | | -``` |
25 | | - |
26 | | -Rich operators allow us to define expressions freely. |
27 | | -Note⚠️ For the equality of string, please use `equals(str1,str2)`, while for the equality judgment of number, please use == or != |
28 | | - |
29 | | -#### Supported environment variables |
30 | | -> Environment variables, i.e. supported variables such as Metric values, are used in the expression. When the threshold value is calculated and judged, the variables will be replaced with actual values for calculation. |
31 | | -
|
32 | | -Non fixed environment variables:These variables will change dynamically according to the monitoring Metric object we choose. For example, if we choose **response time Metric of website monitoring**, the environment variables will have `responseTime - This is the response time variable` |
33 | | -If we want to set **when the response time of website monitoring is greater than 400** to trigger an alarm,the expression is `responseTime>400` |
34 | | - |
35 | | -Fixed environment variables(Rarely used):`instance : Row instance value` |
36 | | -This variable is mainly used to calculate multiple instances. For example, we collected `usage`(`usage is non fixed environment variables`) of disk C and disk D, but we only want to set the alarm when **the usage of C disk is greater than 80**. Then the expression is `equals(instance,"c")&&usage>80` |
37 | | - |
38 | | -#### Expression setting case |
39 | | - |
40 | | -1. Website monitoring -> Trigger alarm when the response time is greater than or equal to 400ms |
41 | | -`responseTime>=400` |
42 | | -2. API monitoring -> Trigger alarm when the response time is greater than 3000ms |
43 | | -`responseTime>3000` |
44 | | -3. Entire site monitoring -> Trigger alarm when URL(instance) path is `https://baidu.com/book/3` and the response time is greater than 200ms |
45 | | -`equals(instance,"https://baidu.com/book/3")&&responseTime>200` |
46 | | -4. MYSQL monitoring -> status Metric group -> Trigger alarm when hreads_running(number of running threads) Metric is greater than 7 |
47 | | -`threads_running>7` |
48 | | - |
49 | | -Other issues can be fed back through the communication group ISSUE! |
| 7 | +> When configuring threshold alerts, it is necessary to set up threshold trigger expressions. The system calculates whether to trigger an alert based on the expression and the monitored metric values. Here, we provide a detailed explanation of expression usage. |
| 8 | +
|
| 9 | +#### Supported Operators in Expressions |
| 10 | + |
| 11 | +| Operator (Visual Configuration) | Operator (Expression Configuration) | Supported Types | Description | |
| 12 | +| ------------------------------- | ----------------------------------- | ------------------------- | -------------------------- | |
| 13 | +| Equals | equals(str1,str2) | String | Check if strings are equal | |
| 14 | +| Not Equals | !equals(str1,str2) | String | Check if strings are not equal | |
| 15 | +| Contains | contains(str1,str2) | String | Check if string contains | |
| 16 | +| Not Contains | !contains(str1,str2) | String | Check if string does not contain | |
| 17 | +| Matches | matches(str1,str2) | String | Check if string matches regex | |
| 18 | +| Not Matches | !matches(str1,str2) | String | Check if string does not match regex | |
| 19 | +| Exists | exists(obj) | String, Numeric, Time | Check if value exists | |
| 20 | +| Not Exists | !exists(obj) | String, Numeric, Time | Check if value does not exist | |
| 21 | +| Greater than | obj1 > obj2 | Numeric, Time | Check if value is greater than | |
| 22 | +| Less than | obj1 < obj2 | Numeric, Time | Check if value is less than | |
| 23 | +| Greater than or Equal to | obj1 >= obj2 | Numeric, Time | Check if value is greater than or equal to | |
| 24 | +| Less than or Equal to | obj1 <= obj2 | Numeric, Time | Check if value is less than or equal to | |
| 25 | +| Not Equal to | obj1 != obj2 | Numeric, Time | Check if values are not equal | |
| 26 | +| Equal to | obj1 == obj2 | Numeric, Time | Check if values are equal | |
| 27 | + |
| 28 | +#### Expression Function Library List |
| 29 | + |
| 30 | +| Supported Function Library | Description | |
| 31 | +| -------------------------------- | -------------------------------------------------------------- | |
| 32 | +| condition ? trueExpression : falseExpression | Ternary operator | |
| 33 | +| toDouble(str) | Convert string to Double type | |
| 34 | +| toBoolean(str) | Convert string to Boolean type | |
| 35 | +| toInteger(str) | Convert string to Integer type | |
| 36 | +| array[n] | Retrieve the nth element of an array | |
| 37 | +| * | Multiplication | |
| 38 | +| / | Division | |
| 39 | +| % | Modulo | |
| 40 | +| ( and ) | Parentheses for controlling the order of operations in logical or mathematical expressions | |
| 41 | +| + | Addition | |
| 42 | +| - | Subtraction | |
| 43 | +| && | Logical AND operator | |
| 44 | +| \|\| | Logical OR operator | |
| 45 | + |
| 46 | +#### Supported Environment Variables |
| 47 | + |
| 48 | +> Environment variables refer to variables supported by metric values, used in expressions. During threshold calculation and judgment, these variables will be replaced with actual values. |
| 49 | +
|
| 50 | +Non-fixed Environment Variables: These variables change dynamically based on the selected monitoring metric. For example, if we choose **response time metric for website monitoring**, the environment variable would be `responseTime - this represents response time variable`. If we want to set an alert trigger for **response time greater than 400 for website monitoring**, the expression would be `responseTime>400`. |
| 51 | + |
| 52 | +Fixed Environment Variables (Less commonly used): `instance: instance value` |
| 53 | +This variable is mainly used for calculations involving multiple instances. For instance, if we collect usage metrics for C drive and D drive (`usage` being a non-fixed environment variable), and we only want to set an alert for **usage greater than 80 for the C drive**, the expression would be `equals(instance,"c")&&usage>80`. |
| 54 | + |
| 55 | +#### Expression Configuration Examples |
| 56 | + |
| 57 | +1. Website Monitoring -> Alert when response time is greater than or equal to 400ms |
| 58 | + `responseTime>=400` |
| 59 | +2. API Monitoring -> Alert when response time is greater than 3000ms |
| 60 | + `responseTime>3000` |
| 61 | +3. Overall Monitoring -> Alert when response time for URL (instance) path 'https://baidu.com/book/3' is greater than 200ms |
| 62 | + `equals(instance,"https://baidu.com/book/3")&&responseTime>200` |
| 63 | +4. MYSQL Monitoring -> Alert when 'threads_running' metric under 'status' exceeds 7 |
| 64 | + `threads_running>7` |
| 65 | + |
| 66 | +If you encounter any issues, feel free to discuss and provide feedback through our community group or ISSUE tracker! |
0 commit comments