SkyWalking 8.3.0部署

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/ 有问题的话要开vpn

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(<generated>)
	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

/**
 * <p>
 * SkyWalking告警对象
 * </p>
 *
 * @author ltx
 * #Webhook
 * SkyWalking 的告警 Webhook 要求对等方是一个 Web 容器. 告警的消息会通过 HTTP 请求进行发送, 请求方法为 POST, Content-Type 为 application/json, JSON 格式基于 List<org.apache.skywalking.oap.server.core.alarm.AlarmMessage, 包含以下信息.
 *
 * scopeId. 所有可用的 Scope 请查阅 org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.
 * name. 目标 Scope 的实体名称.
 * id0. Scope 实体的 ID.
 * id1. 未使用.
 * ruleName. 您在 alarm-settings.yml 中配置的规则名.
 * alarmMessage. 报警消息内容.
 * startTime. 告警时间, 位于当前时间与 UTC 1970/1/1 之间.
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "SkyWalking告警对象")
public class AlarmMessageDto implements Serializable {
    @ApiModelProperty(value = "scopeId")
    private Long scopeId;

    @ApiModelProperty(value = "目标Scope的实体名称")
    private String name;

    @ApiModelProperty(value = "Scope实体的ID")
    private String id0;

    @ApiModelProperty(value = "未使用")
    private String id1;

    @ApiModelProperty(value = "在alarm-settings.yml中配置的规则名")
    private String ruleName;

    @ApiModelProperty(value = "告警消息内容")
    private String alarmMessage;

    @ApiModelProperty(value = "告警时间")
    private Long startTime;
}

 

webhook controller

/**
 * <p>
 * SkyWalking APM监控
 * SkyWalking 的告警 Webhook 可对接钉钉
 * </p>
 *
 * @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<Boolean> skyWalkingWebhook(@RequestBody @ApiParam(value = "告警列表") List<AlarmMessageDto> 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

 

<dependency>
    <groupId>org.apache.skywalking</groupId>
    <artifactId>apm-toolkit-trace</artifactId>
    <version>8.3.0</version>
    <scope>provided</scope>
</dependency>

<!--打印skywalking的TraceId到日志-->
<dependency>
    <groupId>org.apache.skywalking</groupId>
    <artifactId>apm-toolkit-logback-1.x</artifactId>
    <version>8.3.0</version>
</dependency>

logback-spring.xml

 

<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
    <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] %highlight(%5level) --- [%16.16thread] %cyan(%-40logger{40}) %4line : %msg%n</pattern>
    </layout>
</encoder>

自定义端点

 

默认埋点了mvc和mysql对接
自定义埋点:方法上加 @Trace
记录参数和返回信息,在方法上增加@Tag或者@Tags
@ApiOperation("根据ids获取用户信息")
@GetMapping("/getUsersByUserIds")
@Trace
@Tags({@Tag(key = "param1", value = "arg[0]"), @Tag(key = "R", value = "returnedObj")})
public R<List<SysUser>> getUsersByUserIds(@RequestParam @ApiParam(value = "用户ids") Collection<Integer> userIds) {
    return R.ok(sysUserService.listByIds(userIds));
}

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小绿豆

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值