dql1978dql1978 2017-06-17 07:31
浏览 421
已采纳

Prometheus alertmanager的处理顺序

I'm currently redesigning an existing alert configuration of alert manager. There's only a small issue, I don't understand alert manager fully.

Assume I have the following configuration;

routes:

match:
  severity:"warning"
receiver: "hipchat-teamX"

match_re:
  application:"(foo|bar)"
receiver: "hipchat-teamX"

match_re:
  application:"(barfoo.*)"
receiver: "hipchat-teamY"

Then an alert is firing from Prometheus with the following values, application:"barfooOne" severity:"warning"

To which receiver will the alert send? And why?

Does alert manager handle an up down structure?

And when do you decide to declare a new child of the route (routes)?

  • 写回答

2条回答 默认 最新

  • doujia1679 2017-07-07 13:42
    关注

    I found an solution with some help of the developers at GitHub.

    You may see the processing of the config in the following way, similar to an if statement with AND and OR declarations.

    Alertmanager applies the config to a up-down, left-right principle. Where the up-down is similar to the OR statement you will use in a regular if statement.

    When you're going from left to right, you could compare it with the AND statement in if commands.

    Further you should keep in mind that when the first statement matches, and there are no 'AND' parts declared, alertmanager pushes the alert to the receiver without looking further for any other match. So in the example above, if prometheus fires an alert with the following labels {severity: "warning", application: "barfoo"}, the alert is sent to hipchat-teamX.

    Note the following, the label value of application matches the route for hipchat-teamY. So why it isn't sent to that route? The answer is not that diffucult, it's because the first one matches, and there are no subroutes declared, so it will stop looking for any other match.

    However, if the alertmanager has config like the code below, the alert will be sent to the receiver '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"
    

    To make it a bit more advanced, asume prometheus sends a new alert with the following labels {severity: "critical", application: "barfoo"}. With the following config, the alert is routed to hipchat-teamX.

    And with the labels {severity: "critical", application: "foo"}, the alert is sent to 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"
    

    I hope this explanation will help others who are experiencing the same issue or question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮