SkyWalking for Java

kyaa111 11月前 ⋅ 488 阅读

Skywalking的性能损耗接近3%

一. Docker配置

  1. docker pull apache/skywalking-oap-server:9.4.0-java17
  2. docker pull apache/skywalking-ui:v9.4.0-java17
  3. docker pull elasticsearch:8.7.1
  4. docker pull kibana:8.7.1
  5. docker run --name elasticsearch --network rootnet --ip 172.19.0.8 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms128m -Xmx512m" -e xpack.security.enabled=false -d elasticsearch:8.7.1. 存储oap收集的数据
  6. docker run --name skywalking-oap --network rootnet --ip 172.19.0.9 --restart always -d -p 11800:11800 -p 12800:12800 --privileged=true -e TZ=Asia/Shanghai -e SW_STORAGE=elasticsearch -e SW_STORAGE_ES_CLUSTER_NODES=172.19.0.8:9200 -e SW_CLUSTER_INTERNAL_COM_HOST=172.19.0.9 -e SW_CLUSTER_INTERNAL_COM_PORT=11800 -e SW_CLUSTER=nacos -e SW_CLUSTER_NACOS_HOST_PORT=172.19.0.5:8848 -e SW_CLUSTER_NACOS_NAMESPACE=19a0fa32-ed2e-40f1-a1e1-aae8c81d8cf8 -e SW_CLUSTER_NACOS_USERNAME=nacos -e SW_CLUSTER_NACOS_PASSWORD=nacos -v /etc/localtime:/etc/localtime:ro apache/skywalking-oap-server:9.4.0-java17. (负责收集和处理来自Agent的数据,并将其存储到可选的存储系统中(例如Elasticsearch或TiDB)。因此,SkyWalking OAP可以看作是SkyWalking的数据集中器)
  7. docker run --name skywalking-ui --network rootnet --ip 172.19.0.10 --restart always -p 7099:8080 -d --privileged=true -e TZ=Asia/Shanghai -e SW_OAP_ADDRESS=[http://172.19.0.9:12800](http://172.19.0.9:12800) -v /etc/localtime:/etc/localtime:ro apache/skywalking-ui:v9.4.0-java17.
  8. docker run --name kibana -d --network rootnet --ip 172.19.0.11 -p 5601:5601 -v /usr/local/kibana/config/:/usr/share/kibana/config/ kibana:8.7.1. /usr/local/kibana/config下有两个配置文件
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://172.19.0.8:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
## Node command line options
## See `node --help` and `node --v8-options` for available options
## Please note you should specify one option per line

## max size of old space in megabytes
#--max-old-space-size=4096

## do not terminate process on unhandled promise rejection
 --unhandled-rejections=warn

  1. kibana中, 点击 discover, 点击 Create a data view. Index pattern 输入 sw_log

二. Java配置

  1. 配置agent. -javaagent:/path/skywalking-agent.jar -Dskywalking.agent.service_name=user-api -Dskywalking.collector.backend_service=192.168.222.129:11800. user-api是当前服务的名称. 192.168.222.129:11800是oap服务grpc地址
  2. 配置日志传输.

添加依赖

<dependency>
   <groupId>org.apache.skywalking</groupId>
   <artifactId>apm-toolkit-logback-1.x</artifactId>
   <version>{project.release.version}</version>
</dependency>

logback-spring.xml如下


<!-- 传输到skywalking -->
<appender name="skywalking-log" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
  <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
    <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</pattern>
    </layout>
  </encoder>
</appender>

<root level="info">
    <appender-ref ref="skywalking-log"/>
</root>

效果图

1.png

2.png

3.png

4.png

性能剖析模块被删除了

https://github.com/apache/skywalking/discussions/8246

不支持添加log字段. 日志模块完全可以使用ELK代替, 将TraceID复制出来后放在ELK中再查询. 将日志再传输至skywalking也会带来一定的损耗

https://github.com/apache/skywalking/discussions/9242

ref:

https://skywalking.apache.org/docs/skywalking-java/v8.15.0/en/setup/service-agent/java-agent/application-toolkit-logback-1.x/

https://juejin.cn/post/7049920780569673736