Prometheus alertmanager 的处理顺序
Prometheus alertmanager order of handling
我目前正在重新设计警报管理器的现有警报配置。只有一个小问题,我不完全了解警报管理器。
假设我有以下配置;
routes:
match:
severity:"warning"
receiver: "hipchat-teamX"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamX"
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
然后从 Prometheus 发出警报,应用程序具有以下值:"barfooOne"
严重性:"warning"
警报将发送给哪个接收者?为什么?
警报管理器是否处理上下结构?
你什么时候决定声明一个新的子路由(routes)?
我也是新手,所以我只能脱离我的理解,在你的场景中,第二个接收者将收到警报,因为默认情况下 continue
是 false
。
我在 GitHub 的开发人员的帮助下找到了解决方案。
您可能会看到配置的处理方式如下,类似于带有 AND 和 OR 声明的 if 语句。
Alertmanager 将配置应用于上下左右原则。其中 up-down 类似于您将在常规 if 语句中使用的 OR 语句。
当你从左到右时,你可以将它与if命令中的AND语句进行比较。
此外,您应该记住,当第一个语句匹配时,并且没有声明 'AND' 部分,alertmanager 会将警报推送给接收者,而不会进一步寻找任何其他匹配项。因此,在上面的示例中,如果 prometheus 触发带有以下标签的警报 {severity: "warning", application: "barfoo"},警报将发送到 hipchat-teamX.
注意以下几点,application的标签值与hipchat-teamY的路由匹配。那么为什么它不发送到那条路线呢?答案并不难,因为第一个匹配,并且没有声明子路由,所以它将停止寻找任何其他匹配。
但是,如果 alertmanager 具有如下代码的配置,则警报将发送到接收者 'hipchat-teamY'。
routes:
match:
severity:"warning"
receiver: "hipchat-teamX"
routes:
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamX"
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
为了让它更高级一些,假设 prometheus 发送了一个带有以下标签的新警报 {severity: "critical", application: "barfoo"}。使用以下配置,警报将路由到 hipchat-teamX。
并使用标签{严重性:"critical",应用程序:"foo"},将警报发送到 hipchat-teamY。
routes:
match:
severity:"warning"
receiver: "hipchat-teamX"
routes:
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamX"
match:
severity:"critical"
receiver: "hipchat-teamY"
routes:
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamX"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamY"
我希望这个解释能帮助遇到同样问题或疑问的其他人。
我目前正在重新设计警报管理器的现有警报配置。只有一个小问题,我不完全了解警报管理器。
假设我有以下配置;
routes:
match:
severity:"warning"
receiver: "hipchat-teamX"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamX"
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
然后从 Prometheus 发出警报,应用程序具有以下值:"barfooOne" 严重性:"warning"
警报将发送给哪个接收者?为什么?
警报管理器是否处理上下结构?
你什么时候决定声明一个新的子路由(routes)?
我也是新手,所以我只能脱离我的理解,在你的场景中,第二个接收者将收到警报,因为默认情况下 continue
是 false
。
我在 GitHub 的开发人员的帮助下找到了解决方案。
您可能会看到配置的处理方式如下,类似于带有 AND 和 OR 声明的 if 语句。
Alertmanager 将配置应用于上下左右原则。其中 up-down 类似于您将在常规 if 语句中使用的 OR 语句。
当你从左到右时,你可以将它与if命令中的AND语句进行比较。
此外,您应该记住,当第一个语句匹配时,并且没有声明 'AND' 部分,alertmanager 会将警报推送给接收者,而不会进一步寻找任何其他匹配项。因此,在上面的示例中,如果 prometheus 触发带有以下标签的警报 {severity: "warning", application: "barfoo"},警报将发送到 hipchat-teamX.
注意以下几点,application的标签值与hipchat-teamY的路由匹配。那么为什么它不发送到那条路线呢?答案并不难,因为第一个匹配,并且没有声明子路由,所以它将停止寻找任何其他匹配。
但是,如果 alertmanager 具有如下代码的配置,则警报将发送到接收者 'hipchat-teamY'。
routes:
match:
severity:"warning"
receiver: "hipchat-teamX"
routes:
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamX"
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
为了让它更高级一些,假设 prometheus 发送了一个带有以下标签的新警报 {severity: "critical", application: "barfoo"}。使用以下配置,警报将路由到 hipchat-teamX。
并使用标签{严重性:"critical",应用程序:"foo"},将警报发送到 hipchat-teamY。
routes:
match:
severity:"warning"
receiver: "hipchat-teamX"
routes:
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamY"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamX"
match:
severity:"critical"
receiver: "hipchat-teamY"
routes:
match_re:
application:"(barfoo.*)"
receiver: "hipchat-teamX"
match_re:
application:"(foo|bar)"
receiver: "hipchat-teamY"
我希望这个解释能帮助遇到同样问题或疑问的其他人。