Use Cases
PromQL variable settings are mainly applied in the following scenarios:
-
Differentiated Monitoring Configuration
- Set different alarm thresholds for machines of varying importance
- Configure specific monitoring rules for particular device groups
-
Flexible Monitoring Scope Adjustment
- Quickly switch monitoring target devices
- Dynamically adjust the coverage of monitoring rules
-
Batch Rule Management
- Use the same rule template to adapt to different environments through variables
- Reduce redundant configurations and improve rule maintenance efficiency
What are Variables?
In the context of alert rules, variables are placeholders that can be referenced when defining alert query conditions but are replaced with specific information when alerts are actually triggered. Using variables makes alert messages more specific and personalized while enabling a single alert template to adapt to different requirements in various situations.
Supported Types
- Machine Identifier Variables
In certain scenarios, if you only want to monitor specific network devices, you can use machine identifier variables
After defining the variable name, you can use $ident as a placeholder in the promql query condition. Before the query, the variable will be replaced with the machines filtered by the machine identifier above
mem_available_percent{ident="$ident"}>80
- Network Device Variables
In scenarios where you only want to monitor certain network devices, you can use network device variables
After defining the variable name, you can use $ip as a placeholder in the promql query condition. Before the query, the variable will be replaced with the network devices filtered above
snmp_icmp_packet_loss{agent_host="$ip"}>0
- Threshold Variables
In some scenarios, we manage a group of machines where some machines are special and require different alarm thresholds from others. In this case, we can use threshold variables to configure different thresholds for special machines, as shown below
In the above configuration, machines in the Default Busi Group all have a threshold of 80. If we want to set special thresholds for two machines in this business group, we can add Variable Filtering below the query condition, select these two machines by machine identifier, and set the threshold to 90. This way, only these two machines will have a threshold of 90, while others remain at 80
- Enumeration Variables
In some scenarios, for a particular label, if you only want to monitor certain values, you can use enumeration variables