告警規(guī)則:SkyWalking 的發(fā)行版都會默認(rèn)提供config/alarm-settings.yml文件,可以看源代碼下
rules下配置各種告警規(guī)則
composite-rules下配置組合的規(guī)則
skywalking默認(rèn)支持7中通知疾棵,web跪呈、grpc、微信镇饮、釘釘蜓竹、飛書、華為weLink储藐、slack
告警規(guī)則配置:
# 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
only-as-condition: false
message: Successful rate of endpoint {name} is lower than 75%
Rule name:規(guī)則名稱俱济,也是在告警信息中顯示的唯一名稱。必須以_rule結(jié)尾钙勃,前綴可自定義
Metrics name:度量名稱蛛碌,取值為oal腳本中的度量名,目前只支持long辖源、double和int類型蔚携。詳見Official OAL script
Include names:該規(guī)則作用于哪些實體名稱,比如服務(wù)名克饶,終端名(可選酝蜒,默認(rèn)為全部)
Exclude names:該規(guī)則作不用于哪些實體名稱,比如服務(wù)名矾湃,終端名(可選亡脑,默認(rèn)為空)
Threshold:閾值
OP:操作符,目前支持>、<霉咨、=
Period:多久告警規(guī)則需要被核實一下蛙紫。這是一個時間窗口,與后端部署環(huán)境時間相匹配
Count:在一個Period窗口中途戒,如果values超過Threshold值(按op)坑傅,達(dá)到Count值,需要發(fā)送警報
Silence period:在時間N中觸發(fā)報警后喷斋,在TN -> TN + period這個階段不告警唁毒。 默認(rèn)情況下,它和Period一樣继准,這意味著相同的告警(在同一個Metrics name擁有相同的Id)在同一個Period內(nèi)只會觸發(fā)一次
message:告警消息
告警插件:server-alarm-plugin
首先 看AlarmModuleProvider的prepare? ,會加載alarm-settings.yml枉证,解釋規(guī)則和通知勾子,組裝成alarmRulesWatcher注冊到MetricsNotify
警告消息體
public class AlarmMessage {
private int scopeId;????????所有可用的 Scope 詳見
private String scope;????目標(biāo) Scope 的實體名稱
private String name;????Scope 實體的 ID
private String id0;
private String id1;
private String ruleName;????????告警規(guī)則名稱
private String alarmMessage;????????告警規(guī)則消息
private List?tags;? ? ? ? ? ? ? ? ? ? ? ? tags
private long startTime;? ? ? ? ? ? 開始時間
private transient int period;
private transient boolean onlyAsCondition;
}
如果想在skywalking中實現(xiàn)自己的通知勾子移必,需要實現(xiàn)AlarmCallback接口室谚,實現(xiàn)doAlarm方法,參數(shù)就是AlarmMessage集合
在Rules中加入自己的配置
在NotifyHandler的init方法加入勾子