夜莺-Nightingale
夜莺V7
项目介绍 功能概览
部署升级 部署升级
数据接入 数据接入
告警管理 告警管理
数据查看 数据查看
功能介绍 功能介绍
API FAQ
夜莺V6
项目介绍 架构介绍
快速开始 快速开始
黄埔营
安装部署 安装部署
升级
采集器 采集器
使用手册 使用手册
API API
数据库表结构 数据库表结构
FAQ FAQ
开源生态
Prometheus
版权声明
第1章:天降奇兵 第1章:天降奇兵
第2章:探索PromQL 第2章:探索PromQL
第3章:Prometheus告警处理 第3章:Prometheus告警处理
第4章:Exporter详解 第4章:Exporter详解
第5章:数据与可视化 第5章:数据与可视化
第6章:集群与高可用 第6章:集群与高可用
第7章:Prometheus服务发现 第7章:Prometheus服务发现
第8章:监控Kubernetes 第8章:监控Kubernetes
第9章:Prometheus Operator 第9章:Prometheus Operator
参考资料

The syntax of alert rules expressions essentially involves operations between time series metric data. The logic seeks to find matching Labels (data tags) for metric values; metrics with different Labels cannot be operated on, so it is essential that the Labels remain consistent during operations.

Example:

In time series metric data, each time series is uniquely identified by a metric name (Metric Name) and data tags (Label), formatted as <metric name>{<label name>=<label value>, …}.

When configuring alerts, there are two crucial configurations in the auxiliary settings: value fields and label fields.

Value Field: Specifies a column of the query results as the result of the query condition, understood as the metric name (Metric Name).

Label Field: Specifies which columns of the query results are used as label names and label values for the value field, i.e., the labels (Label).

Alert Expression 001

Alert Expression 002

Transforming the data format based on the above images:

Variable Variable Value Field (Metric Name) Variable Value Label Field (Label) Transformed Time Series Data Format
A $A.price $A.product_name A.price{product_name=} value

If an additional B query condition is added in the alert configuration statistics, and A and B query conditions need to be computed together, then the data tags for both A and B query conditions must be consistent for the operation to proceed. If not, the operation cannot occur. The following images show that the data tags for B are inconsistent with those for A; thus, they cannot be computed together. By renaming fields to unify the data tags, the operations between $A and $B can be achieved.

Alert Expression 003

Alert Expression 004

Arithmetic Operators

Operation Description Example
+ Addition $A + $B
- Subtraction $A - $B
* Multiplication $A * $B
/ Division $A / $B
() Priority ($A - $B) * $C

Comparison Operators

Operation Description Example
== Checks if two values are equal; returns True if equal, otherwise returns False. $A == $B
$A == 0
!= Checks if two values are not equal; returns True if not equal, otherwise returns False. $A != $B
$A.count != 0
> Checks if the left value is greater than the right value; returns True if so, otherwise returns False. $A > $B
$A > 0
< Checks if the left value is less than the right value; returns True if so, otherwise returns False. $A < $B
$A < 0
>= Checks if the left value is greater than or equal to the right value; returns True if so, otherwise returns False. $A >= $B
$A > 0
<= Checks if the left value is less than or equal to the right value; returns True if so, otherwise returns False. $A <= $B
$A <= 0

Timestamp Operations

Current Time Field Description Example
now().Unix() Used to compare the timestamp of query data with the current time. Unix() time format supports only addition and subtraction operations. $A.timestamp - now().Unix()

Logical Operators

Operation Description Example
&& Logical AND operator. Returns True if both operands are True; otherwise returns False. $A > 0 && $B < 10
Logical OR operator. Returns True if either operand is True; otherwise returns False. $A + $B > 20

Element Value Comparison

Operation Description Example
in Checks if an element exists in an array; returns true or false. Returns True if the element exists, otherwise returns False. expr:$A in [“admin”, “moderator”]
data:map[string]interface{}{"$.A": “admin”}
expected: true
not in Checks if an element does not exist in an array; returns true or false. Returns True if the element does not exist, otherwise returns False. expr:$A not in [1, 2, 3]
data:map[string]interface{}{"$.A": 5}
expected: true

String Contains and Not Contains

Operation Description Example
contains Checks if an element exists in an array; returns true or false. Returns True if the element exists, otherwise returns False. expr:$A contains $B
data: map[string]interface{}{"$.A": “hello world”, “$.B”: “world”}
expected: true
not contains Checks if one string does not contain another string; returns true or false. Returns True if it does not contain, otherwise returns False. expr: $.A contains $.B
data:map[string]interface{}{"$.A": “hello world”, “$.B”: “go”}
expected: false

Regular Expression Matching

Operation Description Example
matches Checks if a string matches a given regular expression; returns true or false. Returns True if it matches, otherwise returns False. expr:$A matches $B
data:map[string]interface{}{"$.A": “123”, “$.B”: “^[0-9]+$”}
expected: true

Value Range Check

Operation Description Example
between Checks if a value is within a specified range; returns true or false. Returns True if within the range, otherwise returns False. expr:between($.A, [100,200])
data: map[string]interface{}{"$.A": 155.0}
expected: true
not between Checks if a value is not within a specified range; returns true or false. Returns True if not within the range, otherwise returns False. expr: not between($.A, [100.3,200.3])
data: map[string]interface{}{"$.A": 155.1}
expected: false

More reference documentation: MySQL Alert Expression Use Cases

快猫星云 联系方式 快猫星云 联系方式
快猫星云 联系方式
快猫星云 联系方式
快猫星云 联系方式
快猫星云
OpenSource
开源版
Flashcat
Flashcat