当前位置:   article > 正文

skywalking告警相关配置

skywalking告警相关配置

告警基本流程
        skywalking发送告警的基本原理是每隔一段时间轮询skywalking-collector收集到的链路追踪的数据,再根据所配置的告警规则(如服务响应时间、服务响应时间百分比)等,如果达到阈值则发送响应的告警信息。发送告警信息是以线程池异步的方式调用webhook接口完成,(具体的webhook接口可以使用者自行定义),从而开发者可以在指定的webhook接口中自行编写各种告警方式,钉钉告警、邮件告警等等。

告警相关配置
开启skywalking相关告警配置,编辑 config/alarm-settings.yml,打开之后如下所示:rules即为需要配置的告警规则的列表;第一个规则‘endpoint_percent_rule’,是规则名,不能重复且必须以’_rule’为结尾;其中里面的属性:
属性    含义
metrics-name    指定的规则(与规则名不同,这里是对应的告警中的规则map,具体可查看https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/backend-alarm.md#list-of-all-potential-metrics-name,其中一些常见的,endpoint_percent_rule——端点相应半分比告警,service_percent_rule——服务相应百分比告警)
threshold    阈值,与metrics-name和下面的比较符号相匹配
op    比较操作符,可以设定>,<,=,即如metrics-name: endpoint_percent, threshold: 75,op: < ,表示如果相应时长小于平均75%则发送告警
period    多久检查一次当前的指标数据是否符合告警规则
counts    达到多少次告警后,发送告警消息
silence-period    在多久之内,忽略相同的告警消息
message    告警消息内容
include-names    使用本规则告警的服务列表

  1. rules:
  2. # Rule unique name, must be ended with `_rule`.
  3. endpoint_percent_rule:
  4. # Metrics value need to be long, double or int
  5. metrics-name: endpoint_percent
  6. threshold: 75
  7. op: <
  8. # The length of time to evaluate the metrics
  9. period: 10
  10. # How many times after the metrics match the condition, will trigger alarm
  11. count: 3
  12. # How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
  13. silence-period: 10
  14. service_percent_rule:
  15. metrics-name: service_percent
  16. # [Optional] Default, match all services in this metrics
  17. include-names:
  18. - service_a
  19. - service_b
  20. threshold: 85
  21. op: <
  22. period: 10
  23. count: 4
  24. webhooks:
  25. - http://127.0.0.1//alarm/test

webhook接口url的定义(地址自定义),除了规则制定之外,还有达到告警规则后,需要skywalking调用的webhook接口,如上所示的配置,一定要注意url的缩进,之前缩进两个空格,一直没生效。
        配置完成之后,重启skywalking生效;

告警webhook接口对接
        编写上述webhook对接的接口,http://127.0.0.1//alarm/test ,当前版本webhook接口调用的方式是post+requestbody,而body中的内容如下:

  1. [
  2. {
  3. "scopeId":1, //指的是告警的范围类型(源码中有定义常量org.apache.skywalking.oap.server.core.source.DefaultScopeDefine)
  4. "name":"gateway", //告警服务名称
  5. "id0":3, //与服务名称一一匹配
  6. "id1":0, //暂时未做使用
  7. "alarmMessage":"Response time of service gateway is more than 1000ms in 3 minutes of last 10 minutes.",
  8. "startTime":1569552742633 //告警发起时间戳
  9. },
  10. {
  11. "scopeId":1,
  12. "name":"en-exercise",
  13. "id0":2,
  14. "id1":0,
  15. "alarmMessage":"Response time of service en-exercise is more than 1000ms in 3 minutes of last 10 minutes.",
  16. "startTime":1569552742633
  17. }
  18. ]

于是定义的接口如下:

  1. @RequestMapping("/alarm")
  2. @RestController
  3. public class AlarmController {
  4. @Autowired
  5. AlarmService alarmService;
  6. @RequestMapping(value = "/test",method = RequestMethod.POST)
  7. public void alarm(@RequestBody List<AlarmMessageDto> alarmMessageList){
  8. System.out.println(alarmMessageList.toString());
  9. //具体处理告警信息
  10. alarmService.doAlarm(alarmMessageList);
  11. }
  12. }
  13. //实体类
  14. @Data
  15. public class AlarmMessageDto {
  16. private int scopeId;
  17. private String name;
  18. private int id0;
  19. private int id1;
  20. private String alarmMessage;
  21. private long startTime;
  22. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/236426
推荐阅读
相关标签
  

闽ICP备14008679号