1 告警功能简介

Skywalking每隔一段时间根据收集到的链路追踪的数据和配置的告警规则(如服务响应时间、服务响应时间百分比)等,判断如果达到阈值则发送相应的告警信息。发送告警信息是通过调用webhook接口完成,具体的webhook接口可以使用者自行定义,从而开发者可以在指定的webhook接口中编写各种告警方式,比如邮件、短信等。告警的信息也可以在RocketBot中查看到。

以下是默认的告警规则配置,位于skywalking安装目录下的config文件夹下 alarm-settings.yml 文件

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.# Sample alarm rules.
rules:# Rule unique name, must be ended with `_rule`.service_resp_time_rule:metrics-name: service_resp_timeop: ">"threshold: 1000period: 10count: 3silence-period: 5message: Response time of service {name} is more than 1000ms in 3 minutes of last 10 minutes.service_sla_rule:# Metrics value need to be long, double or intmetrics-name: service_slaop: "<"threshold: 8000# The length of time to evaluate the metricsperiod: 10# How many times after the metrics match the condition, will trigger alarmcount: 2# How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.silence-period: 3message: Successful rate of service {name} is lower than 80% in 2 minutes of last 10 minutesservice_p90_sla_rule:# Metrics value need to be long, double or intmetrics-name: service_p90op: ">"threshold: 1000period: 10count: 3silence-period: 5message: 90% response time of service {name} is more than 1000ms in 3 minutes of last 10 minutesservice_instance_resp_time_rule:metrics-name: service_instance_resp_timeop: ">"threshold: 1000period: 10count: 2silence-period: 5message: Response time of service instance {name} is more than 1000ms in 2 minutes of last 10 minutes
#  Active endpoint related metrics alarm will cost more memory than service and service instance metrics alarm.
#  Because the number of endpoint is much more than service and instance.
#
#  endpoint_avg_rule:
#    metrics-name: endpoint_avg
#    op: ">"
#    threshold: 1000
#    period: 10
#    count: 2
#    silence-period: 5
#    message: Response time of endpoint {name} is more than 1000ms in 2 minutes of last 10 minuteswebhooks:
#  - http://127.0.0.1/notify/
#  - http://127.0.0.1/go-wechat/

以上文件定义了默认的4种规则:

  1. 最近3分钟内服务的平均响应时间超过1秒
  2. 最近2分钟服务成功率低于80%
  3. 最近3分钟90%服务响应时间超过1秒
  4. 最近2分钟内服务实例的平均响应时间超过1秒

规则中的参数属性如下:

属性

含义

metrics-name

oal脚本中的度量名称

threshold

阈值,与metrics-name和下面的比较符号相匹配

op

比较操作符,可以设定>,<,=

period

多久检查一次当前的指标数据是否符合告警规则,单位分钟

count

达到多少次后,发送告警消息

silence-period

在多久之内,忽略相同的告警消息

message

告警消息内容

include-names

本规则告警生效的服务列表

注意:
        webhooks可以配置告警产生时的调用地址。

2 告警功能测试代码

编写告警功能接口来进行测试,创建skywalking_alarm项目。可以直接使用资源中的skywalking_alarm.jar 。

AlarmController:

package com.itcast.skywalking_alarm.controller;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class AlarmController {//每次调用睡眠1.5秒,模拟超时的报警@GetMapping("/timeout")public String timeout(){try {Thread.sleep(1500);} catch (InterruptedException e) {e.printStackTrace();}return "timeout";}
}

该接口主要用于模拟超时,多次调用之后就可以生成告警信息。

WebHooks:

package com.itcast.skywalking_alarm.controller;import com.itcast.skywalking_alarm.pojo.AlarmMessage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;import java.util.ArrayList;
import java.util.List;@RestController
public class WebHooks {private List<AlarmMessage> lastList = new ArrayList<>();@PostMapping("/webhook")public void  webhook(@RequestBody List<AlarmMessage> alarmMessageList){lastList = alarmMessageList;}@GetMapping("/show")public List<AlarmMessage> show(){return lastList;}
}

注意:

产生告警时会调用webhook接口,该接口必须是Post类型,同时接口参数使用RequestBody。参

数格式为:

[{"scopeId":1,"scope":"SERVICE","name":"serviceA","id0":12,"id1":0,"ruleName":"service_resp_time_rule","alarmMessage":"alarmMessage xxxx","startTime":1560524171000},{"scopeId":1,"scope":"SERVICE","name":"serviceB","id0":23,"id1":0,"ruleName":"service_resp_time_rule","alarmMessage":"alarmMessage yyy","startTime":1560524171000}
]

AlarmMessage:

package com.itcast.skywalking_alarm.pojo;public class AlarmMessage {private int scopeId;private String name;private int id0;private int id1;//告警的消息private String alarmMessage;//告警的产生时间private long startTime;public int getScopeId() {return scopeId;}public void setScopeId(int scopeId) {this.scopeId = scopeId;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getId0() {return id0;}public void setId0(int id0) {this.id0 = id0;}public int getId1() {return id1;}public void setId1(int id1) {this.id1 = id1;}public String getAlarmMessage() {return alarmMessage;}public void setAlarmMessage(String alarmMessage) {this.alarmMessage = alarmMessage;}public long getStartTime() {return startTime;}public void setStartTime(long startTime) {this.startTime = startTime;}@Overridepublic String toString() {return "AlarmMessage{" +"scopeId=" + scopeId +", name='" + name + '\'' +", id0=" + id0 +", id1=" + id1 +", alarmMessage='" + alarmMessage + '\'' +", startTime=" + startTime +'}';}
}

实体类用于接口告警信息。

3 部署测试

首先需要修改告警规则配置文件:config文件夹下 alarm-settings.yml 文件,将webhook地址修改为:

webhooks: - http://127.0.0.1:8089/webhook

然后重启skywalking。

1、将 skywalking_alarm.jar 上传至 /usr/local/skywalking 目录下。

2、启动skywalking_alarm应用,等待启动成功。

java -javaagent:/usr/local/skywalking/apache-skywalking-apm-bin/agent/skywalking-agent.jar -Dskywalking.agent.service_name=skywalking_alarm -jar skywalking_alarm.jar &

3、不停调用接口,接口地址为:http://IP:8089/timeout

4、直到出现告警:

5、查看告警信息接口:http://IP:8089/show

从上图中可以看到,我们已经获取到了告警相关的信息,在生产中使用可以在webhook接口中对接短

信、邮件等平台,当告警出现时能迅速发送信息给对应的处理人员,提高故障处理的速度。

Skywalking(10):告警功能相关推荐

  1. skywalking 之 告警篇

    SkyWalking链路追踪系统-告警篇 原创 仙人技术2021-05-20 23:43:36�0�8著作权 http://cache.baiducontent.com/c?m=5kO2w0jwn2x ...

  2. cacti实现微信告警功能

    背景 近来受朋友所托,为他实现cacti的微信告警功能,但是在印象之中,cacti的thold插件貌似只有邮件告警功能吧?于是花了点时间在网络上搜索了相关信息,发现cacti的微信告警的信息着实很少, ...

  3. prometheus监控告警功能

    prometheus监控K8S 监控告警功能 alertmanager邮箱告警配置 首先开通SMTP服务,QQ邮箱:设置–帐号–开通POP3/SMTP服务,记住生成的密码(其它邮箱同理) 编辑prom ...

  4. SkyWalking触发告警发送邮箱

    以下是默认的告警规则配置,位于skywalking安装目录下的config文件夹下 alarm-settings.yml文件 中: rules:# Rule unique name, must be e ...

  5. 手机上图片信息怎么拉一个矩形框_华为手机EMUI系统隐藏的10个功能,上手体验后,实用性无敌了...

    阅读本文前,请您先点击上面的"蓝色字体",再点击"关注",这样您就可以继续免费收到文章了.每天都有分享,完全是免费订阅,请放心关注. 注:本文转载自网络,如有侵 ...

  6. Zabbix 配置钉钉告警功能

    需求 Zabbix配置钉钉告警和Prometheus配置钉钉告警类似.只不过Zabbix通过钉钉告警是通过Python脚本实现.而Prometheus是通过钉钉的二进制包实现. 我们现在主要来讲解Za ...

  7. windows借鉴linux了吗,Windows应该借鉴Linux的10大功能特征

    Windows应该借鉴Linux的10大功能特征 2009年12月07日 11:11作者:cnbeta编辑:陈涛文章出处:泡泡网原创 分享 泡泡网软件频道12月7日 在可预见的未来,Windows和L ...

  8. html展开插件,分享10款功能强大的HTML5/CSS3应用插件

    本文作者html5tricks,转载请注明出处 今天我们整理了10款功能非常强大的 1.纯CSS3美化 利用CSS3我们可以打造非常具有个性化的用户表单,今天我们就利用CSS3美化Checkbox复选 ...

  9. 安卓10和android区别,华为8月9日发布安卓10.0系统 华为EMUI 10.0功能及适配机型 华为安卓系统和鸿蒙OS区别...

    华为8月9日发布安卓10.0系统 华为EMUI 10.0功能及适配机型 华为安卓系统和鸿蒙OS区别 根据最新消息显示,华为终端官方再次给出消息称,在8月9日华为开发者大会首天,他们将发布新一代基于An ...

最新文章

  1. php文章排序,PHP+Ajax实现后台文章快速排序
  2. 求数组最大数,该数为数组中某两个数相加
  3. hihocoder 1320 压缩字符串(字符串+dp)
  4. 安装汇编环境,写一个最简单的窗口程序
  5. 连续 3 年最受欢迎:Rust,香!
  6. WPF中的一些常用类型转换
  7. ECMAScript 新提案:JSON模块
  8. 多角度分析,通讯时序数据的预测与异常检测挑战
  9. TeamCenter开发系统设计系列之一
  10. sql stuff 函数_SQL STUFF函数概述
  11. 如何操作别人计算机,如何远程控制别人的电脑【图解】
  12. window.location.reload(false);window.location.reload(true);history.Go(0)区别
  13. java中null+和null+null的深入理解
  14. day01_启动程序装载器 IPL
  15. Random随机数和for循环,实现猜数游戏和双色球
  16. 2019辽宁公务员考试行测常识大全:公务员常识40000问(四十八)(2)
  17. 谐音单词背诵,持续补充中......欢迎留言添加
  18. 倒置字符串 将一句话的单词进行倒置,标点不倒置。
  19. 前端面试题(react)
  20. [HLS] dataflow

热门文章

  1. Word04---字体
  2. dvi dp hdmi_HDMI vs DisplayPort vs DVI:您要在新计算机上使用哪个端口?
  3. mk突变点检测_气候突变检测
  4. 计算机基础考证强化训练范文,计算机基础知识题强化训练.doc
  5. 关于电脑电流滋滋声解决方法
  6. yolact模型DCNv2模块编译错误解决方法
  7. linux硬盘对拷 软件,分享|10 个免费的磁盘克隆软件
  8. 杰理ac18芯片_AC6905B/AC6905C杰理JL24脚四合一蓝牙芯片
  9. 杰理之IIC及其他配置定义
  10. java set region_Java Region.setJurisdiction方法代碼示例