做做网站2023,知名网站规划,网站建设手机端管网,吉林省绥中县城乡建设局网站学习本篇文章之前首先要了解一下Sky walking的基础知识 分布式链路追踪工具Sky walking详解
一#xff0c;Sky walking监控数据库
在admin服务中#xff0c;连接数据库查询user表中所有数据 引入依赖 dependencygroupIdmysql/groupIdartifactI…学习本篇文章之前首先要了解一下Sky walking的基础知识 分布式链路追踪工具Sky walking详解
一Sky walking监控数据库
在admin服务中连接数据库查询user表中所有数据 引入依赖 dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion8.0.28/version/dependencydependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.3.2/version/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependency编写userList接口 GetMapping(/userList)public ListUser userList() {return userService.userList();}UserServiceImpl类 Overridepublic ListUser userList() {return this.list();}user表中模拟一百万数据【使用MySQL存储过程】
CREATE PROCEDURE bachInsert2354()
BEGIN
DECLARE n INT DEFAULT 0;
START TRANSACTION;
WHILE n 1000000 DOINSERT INTO user VALUES(NULL,dddd,333333);SET n : n 1;END WHILE;COMMIT;
END;CALL bachInsert2354();访问http://localhost:8086/userList 查看Sky walkingUI界面 拓扑图 链路追踪 查看数据库监控页面 Slow Statements (ms)是慢查询SQL
二Sky walking配置服务的启动日志
将服务的启动日志上传到Sky walking Spring boot集成log4j2 将Spring boot默认的Logback日志框架移除 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdexclusions!-- 去掉springboot默认配置 --exclusiongroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-logging/artifactId/exclusion/exclusions/dependency引入log4j2日志依赖 dependency !-- 引入log4j2依赖 --groupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-log4j2/artifactId/dependency引入Sky walking日志工具包依赖 dependencygroupIdorg.apache.skywalking/groupIdartifactIdapm-toolkit-log4j-2.x/artifactIdversion8.9.0/version/dependency配置log4j2.xml文件【在resource目录下】
?xml version1.0 encodingUTF-8?
configuration statusWARN monitorInterval30!--先定义所有的appender--appenders!-- skywalking输出器 --GRPCLogClientAppender nameSkywalkingLogThresholdFilter leveldebug onMatchACCEPT onMismatchDENY/PatternLayout pattern${LOG_PATTERN}//GRPCLogClientAppender/appendersloggersroot levelINFOappender-ref refSkywalkingLog//root/loggers
/configuration查看UI界面
三配置告警
Sky walking并没有直接配置告警功能而是将需要告警的指标配置到配置文件中配置webhook【网络钩子】通过自定义通知接口然后在实现告警通知告警规则定义在服务端的config/alarm-settings.yml文件中  #配置告警规则
rule:#服务自带的告警规则...#自定义告警规则#规则名称必须全局唯一并且以_rule结尾xxxxxx_rule:#告警的指标名称具体值可以参考下图metrics-name: endpoint_sla#[可选] 指定告警的服务include-names:- serviceA- serviceB#[可选] 排除的服务将不触发告警 exclude-names:- serviceC#[可选] 匹配微服务的名称 通过正则表达式 include-names-regex: instance\_\d#阈值对于不同的指标类型可以设置不用类型的值目前支持long, double or int threshold: 9000 #操作符op: #时间窗口长度单位时间内指标异常就会触发告警 单位是分钟period: 2#累计数量指标符合告警条件达到累计数量后才会触发告警count: 3#静默时间当发生告警后多长时间不再告警默认和period值保持一致silence-period: 10#告警内容触发告警时显示的消息内容 {name} 表示告警的服务名称message: Successful rate of service {name} is lower than 90% in 2 minutes of last 10 minutes配置webhook 告警规则使用原来的实例即可 编写notify接口 PostMapping(/notify)public void alertNotify(RequestBody ListAlertMessage alertMessages) {System.out.println(alert);System.out.println(alertMessages);for (AlertMessage alertMessage : alertMessages) {System.out.println(alertMessage);}}再次访问 http://localhost:8086/userList 触发notify接口 配置钉钉告警机器人
dingtalkHooks:textTemplate: |-{msgtype: text,text: {content: Apache SkyWalking Alarm: \n %s.}} webhooks:- url: 回调地址如【https://oapi.dingtalk.com/robot/send?access_tokendummy_token】secret: 机器人密钥【dummysecret】