写点什么

哇塞!这是我见过的最牛逼的性能监控系统,集强大功能于一身

用户头像
极客good
关注
发布于: 刚刚

selector: ${SW_STORAGE:elasticsearch7}


elasticsearch7:


nameSpace: ${SW_NAMESPACE:""}


clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:192.168.100.14:9200,192.168.100.15:9200,192.168.100.19:9200}


2.2.? 安装 Agent


[https://github.com/apache/skywalking/blob/v8.2.0/docs/en/setup/service-agent/java-agent/README.md](


)


将 agent 目录拷贝至各服务所在的机器上


scp -r ./agent chengjs@192.168.100.12:~/


这里,我将它拷贝至各个服务目录下



plugins 是探针用到各种插件,SkyWalking 插件都是即插即用的,可以把 optional-plugins 中的插件放到 plugins 中


修改 agent/config/agent.config 配置文件,也可以通过命令行参数指定


主要是配置服务名称和后端服务地址


agent.service_name=${SW_AGENT_NAME:user-center}


collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.100.17:11800}


当然,也可以通过环境变量或系统属性的方式来设置,例如:


export SW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800


最后,在服务启动的时候用命令行参数 -javaagent 来指定探针


java -javaagent:/path/to/skywalking-agent/skywalking-agent.jar -jar yourApp.jar


例如:


java -javaagent:./agent/skywalking-agent.jar -Dspring.profiles.active=dev -Xms512m -Xmx1024m -jar demo-0.0.1-SNAPSHOT.jar


3.? 启动服务


修改 webapp/webapp.yml 文件,更改端口号及后端服务地址


server:


port: 9000


collector:


path: /graphql


ribbon:


ReadTimeout: 10000

Point to all backend's restHost:restPort, split by ,

listOfServers: 127.0.0.1:12800


启动服务


bin/startup.sh


或者分别依次启动


bin/oapService.sh


bin/webappService.sh


查看 logs 目录下的日志文件,看是否启动成功


浏览器访问 http://127.0.0.1:9000


4. 告警



编辑 alarm-settings.yml 设置告警规则和通知


[https://github.com/apache/skywalking/blob/v8.2.0/docs/en/setup/backend/backend-alarm.md](


)


重点说下告警通知




为了使用钉钉机器人通知,接下来,新建一个项目


<?xml version="1.0" encoding="UTF-8"?>


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">


<modelVersion>4.0.0</modelVersion>


<parent>


<groupId>org.springframework.boot</groupId>


<artifactId>spring-boot-starter-parent</artifactId>


<version>2.4.0</version>


</parent>


<groupId>com.wt.monitor</groupId>


<artifactId>skywalking-alarm</artifactId>


<version>1.0.0-SNAPSHOT</version>


<name>skywalking-alarm</name>


<properties>


<java.version>1.8</java.version>


</properties>


<dependencies>


<dependency>


<groupId>org.springframework.boot</groupId>


<artifactId>spring-boot-starter-web</artifactId>


</dependency>


<dependency>


<groupId>com.aliyun</groupId>


<artifactId>alibaba-dingtalk-service-sdk</artifactId>


<version>1.0.1</version>


</dependency>


<dependency>


<groupId>commons-codec</groupId>


<artifactId>commons-codec</artifactId>


<version>1.15</version>


</dependency>


<dependency>


<groupId>com.alibaba</groupId>


<artifactId>fastjson</artifactId>


<version>1.2.75</version>


</dependency>


<dependency>


<groupId>org.projectlombok</groupId>


<artifactId>lombok</artifactId>


<optional>true</optional>


</dependency>


</dependencies>


<build>


<plugins>


<plugin>


<groupId>org.springframework.boot</groupId>


<artifactId>spring-boot-maven-plugin</artifactId>


</plugin>


</plugins>


</build>


</project>


可选依赖(不建议引入)


<dependency


<groupId>org.apache.skywalking</groupId>


<artifactId>server-core</artifactId>


<version>8.2.0</version>


</dependency>


定义告警消息实体类


package com.wt.monitor.skywalking.alarm.domain;


import lombok.Data;


import java.io.Serializable;


/**


  • @author ChengJianSheng

  • @date 2020/12/1


*/


@Data


public class AlarmMessageDTO implements Serializable {


private int scopeId;


private String scope;


/**


  • Target scope entity name


*/


private String name;


private String id0;


private String id1;


private String ruleName;


/**


  • Alarm text message


*/


private String alarmMessage;


/**


  • Alarm time measured in milliseconds


*/


private long startTime;


}


发送钉钉机器人消息


package com.wt.monitor.skywalking.alarm.service;


import com.dingtalk.api.DefaultDingTalkClient;


import com.dingtalk.api.DingTalkClient;


import com.dingtalk.api.request.OapiRobotSendRequest;


import com.taobao.api.ApiException;


import lombok.extern.slf4j.Slf4j;


import org.apache.commons.codec.binary.Base64;


import org.springframework.beans.factory.annotation.Value;


import org.springframework.stereotype.Service;


import javax.crypto.Mac;


import javax.crypto.spec.SecretKeySpec;


import java.io.UnsupportedEncodingException;


import java.net.URLEncoder;


import java.security.InvalidKeyException;


import java.security.NoSuchAlgorithmException;


/**


  • https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq

  • @author ChengJianSheng

  • @data 2020/12/1


*/


@Slf4j


@Service


public class DingTalkAlarmService {


@Value("${dingtalk.webhook}")


private String webhook;


@Value("${dingtalk.secret}")


private String secret;


public void sendMessage(String content) {


try {


Long timestamp = System.currentTimeMillis();


String stringToSign = timestamp + "\n" + secret;


Mac mac = Mac.getInstance("HmacSHA256");


mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));


byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));


String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)),"UTF-8");


String serverUrl = webhook + "&timestamp=" + timestamp + "&sign=" + sign;


DingTalkClient client = new DefaultDingTalkClient(serverUrl);


OapiRobotSendRequest request = new OapiRobotSendRequest();


request.setMsgtype("text");


OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();


text.setContent(content);


request.setText(text);


client.execute(request);


} catch (ApiException e) {


e.printStackTrace();


log.error(e.getMessage(), e);


} catch (NoSuchAlgorithmException e) {


e.printStackTrace();


log.error(e.getMessage(), e);


} catch (UnsupportedEncodingException e) {


e.printStackTrace();


log.error(e.getMessage(), e);


} catch (InvalidKeyException e) {


e.printStackTrace();


log.error(e.getMessage(), e);


}


}


}


AlarmController.java


package com.wt.monitor.skywalking.alarm.controller;


import com.alibaba.fastjson.JSON;


import com.wt.monitor.skywalking.alarm.domain.AlarmMessageDTO;


import com.wt.monitor.skywalking.alarm.service.DingTalkAlarmService;


import lombok.extern.slf4j.Slf4j;


import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.web.bind.annotation.PostMapping;


import org.springframework.web.bind.annotation.RequestBo


【一线大厂Java面试题解析+核心总结学习笔记+最新架构讲解视频+实战项目源码讲义】
浏览器打开:qq.cn.hn/FTf 免费领取
复制代码


dy;


import org.springframework.web.bind.annotation.RequestMapping;


import org.springframework.web.bind.annotation.RestController;


import java.text.MessageFormat;


import java.util.List;


/**


  • @author ChengJianSheng

  • @date 2020/12/1


*/


@Slf4j


@RestController


@RequestMapping("/skywalking")


public class AlarmController {


@Autowired


private DingTalkAlarmService dingTalkAlarmService;

用户头像

极客good

关注

还未添加个人签名 2021.03.18 加入

还未添加个人简介

评论

发布
暂无评论
哇塞!这是我见过的最牛逼的性能监控系统,集强大功能于一身