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    使用本规则告警的服务列表

rules:
  # Rule unique name, must be ended with `_rule`.
  endpoint_percent_rule:
    # Metrics value need to be long, double or int
    metrics-name: endpoint_percent
    threshold: 75
    op: <
    # The length of time to evaluate the metrics
    period: 10
    # How many times after the metrics match the condition, will trigger alarm
    count: 3
    # How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
    silence-period: 10
    
  service_percent_rule:
    metrics-name: service_percent
    # [Optional] Default, match all services in this metrics
    include-names:
      - service_a
      - service_b
    threshold: 85
    op: <
    period: 10
    count: 4

webhooks:
 - 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中的内容如下:

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

于是定义的接口如下:

@RequestMapping("/alarm")
@RestController
public class AlarmController {
    @Autowired
    AlarmService alarmService;

    @RequestMapping(value = "/test",method = RequestMethod.POST)
    public void alarm(@RequestBody List<AlarmMessageDto> alarmMessageList){
        System.out.println(alarmMessageList.toString());
        //具体处理告警信息
        alarmService.doAlarm(alarmMessageList);
    }
}
//实体类
@Data
public class AlarmMessageDto {
    private int scopeId;
    private String name;
    private int id0;
    private int id1;
    private String alarmMessage;
    private long startTime;
}

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

懒人烂命

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值