1. An overview of the

1.1 concept

What is Skywalking? FROM http://skywalking.apache.org/, the application of distributed system performance monitoring tools, especially for micro service, cloud native architecture and based on container (Docker, K8s, Mesos) architecture and design. Provides distributed tracking, service grid telemetry analysis, measurement aggregation and visualization integrated solutions.

1.2 Function list

What are the features of Skywalking? FROM http://skywalking.apache.org/

  • Multiple means of monitoring. Monitoring data can be obtained through language probes and Service Mesh.
  • Multiple language automatic probes. Includes Java,.NET Core, and Node.js.
  • Light weight and high efficiency. No big data platform, and a lot of server resources.
  • Modular. There are multiple mechanisms to choose from for UI, storage, and cluster management.
  • Support for alerts.
  • Excellent visualization solution.

    1.3 Overall structure

    What is the overall structure of Skywalking?

    FROM http://skywalking.apache.org/



    The whole structure is divided into four parts: upper, lower, left and right:

    In order to simplify the description, we have dropped Metric related features in favor of Tracing link related features.

  • Agent: collects link information from the application and sends it to the Skywalking OAP server. Tracing data information provided by Skywalking, Zikpin, Jaeger and others is currently supported. At present, we use the Skywalking Agent to collect the Skywalking Tracing data and pass it to the server.
  • The next part of Skywalking OAP is responsible for receiving the Tracing data information sent by the Agent, then conducting Analysis Core, storing it in the external Storage, and finally providing the function of Query.
  • The right section Storage: Tracing data store. At present, it supports ES, MySQL, Sharding Sphere, TIDB and H2. We are currently using ES, and the main consideration is that the Skywalking development team will use ES for their own production environment.
  • The left Skywalking UI: provides the console, views the links, and so on.

    1.4 Official Documents

    Under the address https://github.com/apache/skywalking/tree/master/docs, provides a SkyWalking English document. Considering that most fat friends’ English level is not the same as Nai’s, plus fat friends are relatively unfamiliar with SkyWalking at the beginning, It is recommended to read https://github.com/SkyAPM/document-cn-translation-of-skywalking address, provides a SkyWalking document in Chinese. Considering the purpose of using Skywalking, is to achieve the function of distributed link tracking, so it is best to understand the relevant knowledge. Here are two articles recommended:

  • Official Standards of OpenTracing — Chinese Version
  • Google paper “Dapper, A Tracking System for Large-Scale Distributed Systems”

2. The structures,

2.1 Elasticsearch structures,

Sudo docker pull elasticsearch:7.4.2  mkdir -p /mydata/elasticsearch/config/ mkdir -p /mydata/elasticsearch/data/ echo "http.host: 0.0.0.0 "> > / mydata/elasticsearch/config/elasticsearch yml # instance is created and started: sudo docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \ -e ES_JAVA_OPS="-Xms512m -Xmx512m" \ -v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \ -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \ -v / mydata/elasticsearch/plugins: / usr/share/elasticsearch/plugins \ - d elasticsearch: 7.4.2

Parameter description:

-p 9200:9200 Map port 9200 on the container to port 9200 on the host - the name elasticsearch to current launch container named elasticsearch - v/mydata/elasticsearch/data: / usr/share/elasticsearch/data folder is mounted on the data to the host; - v/mydata/elasticsearch/config/elasticsearch yml: / usr/share/elasticsearch/config/elasticsearch. Yml will mount to the host configuration file; -d daemon -e ES_JAVA_OPS=" -xms256M -xmx256M "Limit memory to small when testing

Visit the elasticsearch:http://IP:9200/

2.2 Download the Skywalking package

For the Skywalking package, there are two ways to get it:

  • Manually compile
  • The official package

In general, we recommend using the official package. Manually compiled, it’s more likely to be a version of a BUG you’re trying or waiting to fix.

2.2.1 the official package

At http://skywalking.apache.org/downloads/, we download the corresponding operating system release. In this case, we chose Binary Distribution for ElasticSearch 7 (Linux) because Naisi is ina Mac environment and wants to use ElasticSearch 7.x for storage. If you want to use Elasticsearch 6.x as your storage, download the Binary Distribution (Linux) version. (1) to download:

$mkdir -p /Users/yunai/skywalking $CD /Users/yunai/skywalking $wget -p /Users/yunai/skywalking $CD /Users/yunai/skywalking http://mirror.bit.edu.cn/apache/skywalking/6.6.0/apache-skywalking-apm-es7-6.6.0.tar.gz

(2) extract:

$tar-zxvf apache-skywalking-apm-es7-6.6.0.tar.gz $CD apache-skywalking-apm-bin-es7 $ls -ls 4 drwxr-xr-x 8 root Root 4096 Sep 9 15:09 agent # Skywalking agent 4 drwxr-xr-x 2 root 4096 Sep 9 15:44 bin # Root 4096 Sep 9 15:44 config # SkyWalking OAP Server 32 -rwxr-xr-x 1 root root 28903 Sep 9 14:32 LICENSE 4 drwxr-xr-x 3 root root 4096 Sep 9 15:44 licenses 32 -rwxr-xr-x 1 root root 31850 Sep 9 14:32 NOTICE 16 drwxr-xr-x 2 root  root 16384 Sep 9 15:22 oap-libs # SkyWalking OAP Server 4 -rw-r--r-- 1 root root 1978 Sep 9 14:32 README.txt 4 drwxr-xr-x 2 root root 4096 Sep 9 15:44 webapp # SkyWalking UI

2.2 Skywalking OAP configuration modification

Modify skywalking/config/application. Yml







Where nameSpace is the ES requested to be installedhttp://IP:9200/The corresponding value of cluster_name returned.

2.3 start

Sskywalking /bin/ sh startup.sh

2.4 access

http://IP:8080/

3.SpringCloud service access Skywalking

3.1 SkyWalking Agent

Most of the time, we configure the SkyWalking Agent with the -javaAgent parameter on the Shell script that starts the project. Given that occasionally we need to be in the IDE and we want to use the Skywalking Agent, we’ll look at it in the IDE section below.

3.1.1 Shell

We need to copy the apache-skywalking-apm-bin/ Agent directory to the server where the Java application is located. In this way, Java applications can be configured to use the Skywalking Agent. Let’s see what’s in the Agent directory:

$ ls -ls total 35176 0 drwxr-xr-x@ 7 yunai staff 224 Dec 24 14:20 activations 0 drwxr-xr-x@ 4 yunai staff 128 Dec 24 14:21 bootstrap-plugins 0 drwxr-xr-x@3 yunai staff 96 Dec 24 14:12 config # SkyWalking Agent 0 drwxr-xr-x@3 yunai Staff 96 Jan 2 19:29 Logs # Skywalking Agent 0 Drwxr-xr-x@13 Yunai Staff 416 Dec 24 14:22 Optional - Plugins DRWXR-XR-X @68 Yunai Staff 2176 DEC 24 14:20 Plugins # 35176-rW-r --r-- @1 Yunai Staff 18006420 DEC 24 14:12 skywalking-agent.jar # SkyWalking Agent
  • For a list of plug-ins provided by the Skywalking Agent, see the Skywalking documentation – Plug-in Support List.

Because Nai Nai is in the unit test, so don’t need to copy, SkyWalking Agent directory is/Users/yunai/SkyWalking/apache – SkyWalking – apm – bin – es7 / Agent /.

② Configure the Java startup script

# Skywalking Agent export SW_AGENT_NAME=demo-application # In general, we use the 'spring.application.name' of the Spring Boot project directly. Export SW_AGENT_COLLECTOR_BACKEND_SERVICES= 127.0.1:11800 # Configure Collector's address Export SW_AGENT_SPAN_LIMIT=2000 # Configure the maximum number of spans for links. In general, no configuration is required and the default is 300. The main consideration, some new Skywalking Agent on the project, the code may be bad. export JAVA_AGENT=-javaagent:/Users/yunai/skywalking/apache-skywalking-apm-bin-es7/agent/skywalking-agent.jar # Skywalking Agent JAR address. $java_agent-jar lab-39-demo-2.2.2.release. Jar $java_agent-jar lab-39-demo-2.2.2.2.release. Jar $java_agent-jar lab-39-demo-2.2.2.2.release.  nohup java -javaagent:/data/application/skywalking/agent/skywalking-agent.jar -Xmx512m -Xms512m -jar ${APP_NAME} - spring. Profiles. The active = dev -- spring. Cloud. Nacos. Discovery. The server - addr = 192.168.0.79:8848 --spring.cloud.nacos.discovery.password=nacos --spring.cloud.nacos.discovery.username=nacos - spring. Cloud. Nacos. Config. Server - addr = 192.168.0.79:8848 > / dev/null > & 1 & 2
  • Through environment variables, the configuration is performed.
  • More variable, can be in/agent/config/agent. The config check. Note that some variables may be commented out, such as agent_span_limit for agent_span_per_segment.

③ Execute the script

3.1.2 the IDEA

We use IDEA uniformly as the development IDE, so ignore the configuration of Eclipse.

For details, refer to the following figure, which is relatively simple:

3.2 Microservice Access Log

3.2.1 Log printing access

  1. Join the rely on

    <dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-logback-1.x</artifactId> The < version > 8.5.0 < / version > < / dependency >
  2. The logback log is collected using GRPC, and the logback.xml fragment is:

    <! > <appender name="grpc_log_info" -- bb0 <appender name="grpc_log_info" 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> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <! > <level>INFO</level> <! > <onMatch>ACCEPT</onMatch> <! -- Operation in case of mismatch: --> <onMismatch>DENY</onMismatch> </filter> </appender> <appender name="grpc_log_error" 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> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <! > <level>ERROR</level> <! > <onMatch>ACCEPT</onMatch> <! > <onMismatch>DENY</onMismatch> </filter> </appender>

    3. Logback. XML is complete with:

    <? The XML version = "1.0" encoding = "utf-8"? > <configuration scan="true" scanPeriod="60 seconds" debug="false"> <! Path value="/data/logs/iot-platform-gateway"/> <! -> <property name="log.pattern" value="%d{HH:mm: ss.sss} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/> <property name="log.pattern.traceId" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - [%tid] - %msg%n"/> <! -- console output --> <! -- <appender name="console" class="ch.qos.logback.core.ConsoleAppender">--> <! -- <encoder>--> <! -- <pattern>${log.pattern}</pattern>--> <! -- </encoder>--> <! -- </appender>--> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <pattern>${log.pattern.traceId}</pattern> </layout> </encoder> </appender> <! > <appender name="grpc_log_info" -- bb0 <appender name="grpc_log_info" 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> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <! > <level>INFO</level> <! > <onMatch>ACCEPT</onMatch> <! -- Operation in case of mismatch: --> <onMismatch>DENY</onMismatch> </filter> </appender> <appender name="grpc_log_error" 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> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <! > <level>ERROR</level> <! > <onMatch>ACCEPT</onMatch> <! --> <onMismatch>DENY</onMismatch> </filter> </appender> <! - the system log output - > < appender name = "file_info" class = "ch. Qos. Logback. Core. Rolling. RollingFileAppender" > <file>${log.path}/info.log</file> <! - circulation policy: based on the time to create a log file - > < rollingPolicy class = "ch. Qos. Logback. Core. Rolling. TimeBasedRollingPolicy" > <! > <fileNamePattern>${log.path}/info.%d{yyyy-mm-dd}. Log </fileNamePattern> <! > <maxHistory>60</maxHistory> </rollingPolicy> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <pattern>${log.pattern.traceId}</pattern> </layout> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <! > <level>INFO</level> <! > <onMatch>ACCEPT</onMatch> <! -- Operation in case of mismatch: --> <onMismatch>DENY</onMismatch> </filter> </appender> <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${log.path}/error.log</file> <! - circulation policy: based on the time to create a log file - > < rollingPolicy class = "ch. Qos. Logback. Core. Rolling. TimeBasedRollingPolicy" > <! > <fileNamePattern>${log.path}/error.%d{yyyy-mm-dd}. Log </fileNamePattern> <! > <maxHistory>60</maxHistory> </rollingPolicy> <! -- <encoder>--> <! -- <pattern>${log.pattern}</pattern>--> <! -- </encoder>--> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <pattern>${log.pattern.traceId}</pattern> </layout> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <! > <level>ERROR</level> <! > <onMatch>ACCEPT</onMatch> <! --> <onMismatch>DENY</onMismatch> </filter> </appender> <! > <logger name="org.dozer" level="error" additivity="false"/> <! - shielding nacos package under the warn level above log - > < logger name = "com. Alibaba. Nacos. Client. Naming" level = "warn" additivity = "false" / > <! > <logger name="org.springframework" level="warn"/> <root level="info"> <appender-ref ="console"/> </root> <! > <root level="info"> <appender-ref ="file_info"/> <appender-ref ="file_error"/> <appender-ref ="file_error" ref="grpc_log_info"/> <appender-ref ref="grpc_log_error"/> </root> </configuration>

4. Modify the agent configuration file: skywalking/agent/config/agent. The config

# Backend service addresses. The collector. Backend_service = ${11800} SW_AGENT_COLLECTOR_BACKEND_SERVICES: 192.168.0.77: The plugin. The toolkit. The GRPC. Reporter. Server_host = ${SW_GRPC_LOG_SERVER_HOST: 192.168.0.77} plugin.toolkit.log.grpc.reporter.server_port=${SW_GRPC_LOG_SERVER_PORT:11800} plugin.toolkit.log.grpc.reporter.max_message_size=${SW_GRPC_LOG_MAX_MESSAGE_SIZE:10485760} plugin.toolkit.log.grpc.reporter.upstream_timeout=${SW_GRPC_LOG_GRPC_UPSTREAM_TIMEOUT:30}

3.2.2. Added support for SpringCloud Gateway

Apm-spring-cloud-gateway -2.1.x plugin-8.5.0.jar apm-spring-cloud-gateway-2.0.x plugin-8.5.0.jar apm-spring-cloud-gateway-2.0.x plugin-8.5.0.jar apm-spring-cloud-gateway-2.0.x plugin-8.5.0.jar apm-spring-cloud-gateway-2.0.x plugin-8.5.0.jar Copy it to your skywalking/optional-plugins directory

3.2.3 Ignore to trace a node (URL)

1. Copy apm-trace-ignore-plugin-8.5.0.jar from your skywalking/plugins directory to your skywalking/optional-plugins directory. Create apm-trace-ignore-plugin.config file under skywalking/agent/config Trace.ignore_path =${SW_AGENT_TRACE_IGNORE_PATH:/api-docs/**} to ignore the trace accessing the swaggerUI

Reference: https://skywalking.apache.org/zh/2020-04-19-skywalking-quick-start/