SkyWalking官网
http://skywalking.apache.org/
官方文档的中文翻译版
https://skyapm.github.io/document-cn-translation-of-skywalking/
安装SkyWalking
1.下载:apache-skywalking-apm-es7-8.3.0.tar.gz
http://skywalking.apache.org/downloads/ 有问题的话要开
2.修改配置文件 config/application.yml
storage:
selector: ${SW_STORAGE:elasticsearch7}
elasticsearch7:
# es命名空间
nameSpace: ${SW_NAMESPACE:"skywalking"}
# es地址
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:192.168.11.223:9200}
UI端口修改
修改webapp/webapp.yml文件
server:
port: 8080
collector:
path: /graphql
ribbon:
ReadTimeout: 10000
# Point to all backend's restHost:restPort, split by ,
listOfServers: 127.0.0.1:12800
3.启动oap和webapp进程, 默认会占用的8080,11800,12800端口
./bin/startup.sh
4.agent的使用
修改配置文件 config/agent.config
# oap地址
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}
5.重启步骤-修改配置文件之后
netstat -ntlp 查询端口占用的进程
kill -9 oap和web进程
./bin/startup.sh
agent配置
将agent目录放到系统上,配置启动参数
---windows---
java -javaagent:F:\ltx\doc\SkyWalking\apache-skywalking-apm-es7-8.3.0\apache-skywalking-apm-bin-es7\agent\skywalking-agent.jar -Dskywalking.agent.service_name=<服务名> -jar <你的包xxxxxxxx>.jar
---linux---
java -javaagent:/data/litingxu/soft/apache-skywalking-apm-bin-es7/agent/skywalking-agent.jar -Dskywalking.agent.service_name=<服务名> -jar <你的包xxxxxxxx>.jar
IDEA代理配置
-javaagent:F:\ltx\doc\SkyWalking\apache-skywalking-apm-es7-8.3.0\apache-skywalking-apm-bin-es7\agent\skywalking-agent.jar -Dskywalking.agent.service_name=<服务名>
异常
异常1:
ERROR 2021-01-09 15:10:52:154 http-nio-8888-exec-8 InstMethodsInter : class[class com.act.controller.ActController] after method[getListPageProcessByStartUserId] intercept failure
java.lang.ClassCastException: org.apache.skywalking.apm.plugin.spring.mvc.commons.JavaxServletRequestHolder cannot be cast to org.apache.skywalking.apm.plugin.spring.mvc.commons.RequestHolder
at org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor.AbstractMethodInterceptor.afterMethod(AbstractMethodInterceptor.java:164)
at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:97)
at com.act.controller.ActController.getListPageProcessByStartUserId(ActController.java)
at com.act.controller.ActController$$FastClassBySpringCGLIB$$12b96605.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
解决:移除spring-boot-devtools
That is the problem of spring-boot-devtools. When using spring-boot-devtools, spring uses RestartClassLoader to load the org.springframework.web.bind.annotation.RequestMapping class.
But the class org.springframework.web.method.HandlerMethod was loaded by AppClassLoader, so the same plugin was loaded with different AgentClassLoader, which resulted in a conversion exception. The spring-boot-devtools package is to implement similar hot deployment functions. I have not yet figured out how to fix this problem. Here is an explanation of this problem. If someone encounters a similar problem, please remove the dependency of spring-boot-devtools.
异常2:
elasticsearch访问503
2021-01-09 17:13:56,904 - org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient - 191 [main] INFO [] - elasticsearch cluster nodes: localhost:9200
2021-01-09 17:14:28,029 - org.apache.skywalking.oap.server.starter.OAPServerBootstrap - 57 [main] ERROR [] - method [HEAD], host [http://localhost:9200], URI [/_template/skywalking_alarm_record?master_timeout=30s], status line [HTTP/1.1 503 Service Unavailable]
org.elasticsearch.ElasticsearchStatusException: method [HEAD], host [http://localhost:9200], URI [/_template/skywalking_alarm_record?master_timeout=30s], status line [HTTP/1.1 503 Service Unavailable]
at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1767) ~[elasticsearch-rest-high-level-client-7.5.0.jar:7.5.0]
解决;es配置增加,注意配置node节点名
# 开启跨域访问支持,默认为false
http.cors.enabled: true
# 跨域访问允许的域名地址
http.cors.allow-origin: "*"
# 通过为 cluster.initial_master_nodes 参数设置符合主节点条件的节点的 IP 地址来引导启动集群
cluster.initial_master_nodes: ["node-1"]
异常3:
端口冲突
修改webapp/webapp.yml
异常4:
性能剖析没数据
去掉 spring-boot-devtools
日志目录
logs目录
skywalking-oap-server.log
webapp-console.log
验证
http://ip:8080/
告警通知
在config/alarm-settings.yml配置
webhooks:
# 自定义的接口实现
# - http://ip:port/url
自带的钉钉机器人:
https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/backend-alarm.md
在config/alarm-settings.yml配置
dingtalkHooks:
textTemplate: |-
{
"msgtype": "text",
"text": {
"content": "Apache SkyWalking Alarm: \n %s."
}
}
webhooks:
- url: https://oapi.dingtalk.com/robot/send?access_token=dummy_token
secret: dummysecret
自带钉钉通知 webhook
自定义实现webhook接收告警信息
告警对象dto
/**
*
* SkyWalking告警对象
*
*
* @author ltx
* #Webhook
* SkyWalking 的告警 Webhook 要求对等方是一个 Web 容器. 告警的消息会通过 HTTP 请求进行发送, 请求方法为 POST, Content-Type 为 application/json, JSON 格式基于 List
webhook controller
/**
*
* SkyWalking APM监控
* SkyWalking 的告警 Webhook 可对接钉钉
*
*
* @author ltx
*
* 在config/alarm-settings.yml配置
* webhooks:
* - http://ip:port/skyWalking/alarmWebhook
*/
@Api(tags = "SkyWalking APM监控", value = "controller")
@RestController
@RequestMapping("/skyWalking")
@Slf4j
public class SkyWalkingController {
@ApiOperation("SkyWalking的告警Webhook")
@PostMapping("/alarmWebhook")
public R skyWalkingWebhook(@RequestBody @ApiParam(value = "告警列表") List alarmMessages) {
log.info("SkyWalking告警: {}", alarmMessages);
return R.ok(true);
}
}
忽略端点
将agent/optional-plugins/apm-trace-ignore-plugin-8.3.0.jar拷贝到agent/plugins
方式有两种:
1.(推荐)在启动参数设置,添加 -Dskywalking.trace.ignore_path=/your/path/1/**,/your/path/2/**
2.将/agent/optional-plugins/apm-trace-ignore-plugin/apm-trace-ignore-plugin.config 复制或剪切到 /agent/config/ 目录下,加上配置
trace.ignore_path=/your/path/1/**,/your/path/2/**
使用Ant Path风格的匹配规则
符号 描述
? 匹配任何单字符
* 匹配0或者任意数量的字符
** 匹配0或者更多的目录
例如
Path 描述
/app/*.x 匹配(Matches)所有在app路径下的.x文件
/app/p?ttern 匹配(Matches) /app/pattern 和 /app/pXttern,但是不包括/app/pttern
/**/example 匹配(Matches) /app/example, /app/foo/example, 和 /example
log日志增加traceId
pom.xml
org.apache.skywalking
apm-toolkit-trace
8.3.0
provided
org.apache.skywalking
apm-toolkit-logback-1.x
8.3.0
logback-spring.xml
%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] %highlight(%5level) --- [%16.16thread] %cyan(%-40logger{40}) %4line : %msg%n
自定义端点
默认埋点了mvc和mysql对接
自定义埋点:方法上加 @Trace
记录参数和返回信息,在方法上增加@Tag或者@Tags
@ApiOperation("根据ids获取用户信息")
@GetMapping("/getUsersByUserIds")
@Trace
@Tags({@Tag(key = "param1", value = "arg[0]"), @Tag(key = "R", value = "returnedObj")})
public R> getUsersByUserIds(@RequestParam @ApiParam(value = "用户ids") Collection userIds) {
return R.ok(sysUserService.listByIds(userIds));
}