An overview,

Recently, I have been studying SkyWalking and intend to use K8S to deploy SkyWalking and connect applications in POD to SkyWalking for service link tracking. Instead of covering the deployment and use of SkyWalking in K8S, this article will show you how to use SkyWalking both manually and docker. In the whole process of practice, I consulted a large number of documents and encountered various problems. Here I will record my own practice process, hoping to provide some help to friends with the same needs.

Introduction to Skywalking

SkyWalking is a popular domestic APM (Application Performance Monitoring) product, Mainly for microservices, Cloud Native and container (Docker, Kubernetes, Mesos) architecture applications. At its core, SkyWalking is a distributed tracking system that is currently a top Project of the Apache Foundation.

The detailed introduction of Skywalking can see the official document: Skywalking website

2. Skywalking Architecture

Logically, SkyWalking is divided into four parts: probe, platform back end, storage and UI, as shown below:

  • Probes collect data and reformat it to SkyWalking’s requirements (different probes support different sources).
  • The platform back end supports data aggregation, analysis, and streaming, covering tracking, metrics, and logging.
  • Storage devices store SkyWalking data through open/pluggable interfaces. You can choose an existing implementation such as ElasticSearch, H2, MySQL, TiDB, InfluxDB, or implement your own.
  • The UI is a highly customizable Web-based interface that allows SkyWalking end users to visualize and manage SkyWalking data.

3. How to automatically report data in SkyWalking

Before you use the link tracing console to trace the application link data, you need to report the application data to the link tracing through the client. SkyWalking reports Java application data to the link tracking console, and the first thing you need to do is bury it. SkyWalking supports both automatic probe (Dubbo, gRPC, JDBC, OkHttp, Spring, Tomcat, Struts, Jedis, etc.) and manual burial (OpenTracing). This paper introduces the automatic burying method.

The principle of Data reported by SkyWalking is shown in the figure below:

Use docker-compose to install Skywalk-oAP-server and Skywalk-UI

Use the following command to install docker-compose in Linux:

yum install -y docker-compose
Copy the code

Create the skywalk-docker-compose. Yaml file with the following command:

vim skywalking-docker-compose.yaml
Copy the code

This starts a standlone container, which stores data in H2 by default, and can be set by viewing the official document for other storage. The skywalk-docker-compose. Yaml file contains the following contents:

version: '3'
services:
  oap:
    image: Apache/skywalking - oap - server: 8.4.0 - es6
    container_name: oap
    restart: always
    ports:
      - 11800: 11800 This is the gRPC port on which the agent reports data
      - 12800: 12800 # UI read data port, this is the HTTP port
  skywaling-ui:
    image: Apache/skywalking - UI: 8.4.0
    container_name: ui
    depends_on:
      - oap
    links:
      - oap
    ports:
      - 8088: 8080
    environment:
      - SW_OAP_ADDRESS=oap:12800

Copy the code

Start Skywalking with the following command:

docker-compose -f skywalking-docker-compose.yaml up -d
Copy the code

To view the startup logs, run the following command:

docker-compose -f skywalking-docker-compose.yaml logs -f 
Copy the code

After successful startup, access:http://localhost:8088, you can see the following interface:

3. Manually connect Spring Boot to SkyWalking

1. Download SkyWalking Agent

Skywalking website to download address: skywalking.apache.org/downloads/

Apache-skywalk-apm-8.4.0.tar. gz (apache-skywalk-apm-8.4.0.tar. gz)

Wget tar ZXVF - https://archive.apache.org/dist/skywalking/8.4.0/apache-skywalking-apm-8.4.0.tar.gz Apache - skywalking - apm - 8.4.0. Tar. GzCopy the code

The decompressed directory structure is as follows:The description of the agent directory is as follows:

2. The Spring Boot project automatically reports data

To report data to the Spring Boot project, you need to configure the Access point and service name of SkyWalking. You can configure them as follows:

Modifying a Configuration File

Open the front download agent/config/agent. The config file, find the following two configurations:

# The service name in UI agent.service_name=${SW_AGENT_NAME:Your_ApplicationName} # Backend service addresses. The collector. Backend_service = ${11800} SW_AGENT_COLLECTOR_BACKEND_SERVICES: 127.0.0.1:Copy the code

After the configuration modification is complete, run the following command to start the Spring Boot project:

java -javaagent:<skywalking-agent-path> -jar spring-boot-demo
Copy the code

Replace it with the absolute path of skywalking-agent.jar in the Agent folder.

Note that the -javaAgent parameter must precede the -jar parameter.

The configuration is performed using command parameters

Service name can be added in the application startup command line – Dskywalking. Agent. The service_name parameter. Skywalking access points can be added in the application startup command line – Dskywalking. Collector. Backend_service parameters. The full command is as follows:

java -javaagent:<skywalking-agent-path> -Dskywalking.agent.service_name=<ServiceName> -Dskywalking.collector.backend_service=<backend-service-addresses>  -jar yourApp.jar
Copy the code

Set this parameter in the startup parameters of IDEA

We can also launch configuration options in IDEAVM optionsPerform the following configuration in:

After the configuration is complete, you can start the project and see the following information printed to the console:

There is no data in skyWalking console, because the interface needs to be accessed before the data will be reported to the console. By constantly calling the interface to test, we can see our calling situation by checking the console again, as shown in the figure below:

Use Docker to deploy Spring Boot and access SkyWalking

Here is the base image selection for Spring Bootskywalking-baseIs contained in the imageopenjdk11skywalking-agentFor more information, see the reference documentation below.

Spring Boot Dockerfile contains the following contents:

FROM apache/ skywalk-base :8.4.0-es6 WORKDIR /app COPY target/ spring-demo-0.0.1-snapshot.jar Spring - demo - 0.0.1 - the SNAPSHOT. Jar ENV SW_AGENT_COLLECTOR_BACKEND_SERVICES = "127.0.0.1:11800 \" SW_AGENT_NAME="my-spring-demo-test-adfasdf" CMD java -javaagent:/skywalking/agent/skywalking-agent.jar \ -jar Spring - demo - 0.0.1 - the SNAPSHOT. The jarCopy the code

Here use environment variables set custom parameters for skywalking, other environment variable configuration can view agent/config/agent. The config file.

Build the image using the following command:

docker build -t spring-boot-demo .
Copy the code

Start the image with the following command:

docker run --rm -p 8080:8080 spring-boot-demo
Copy the code

After successful startup, we can access the test address and check whether there is data reported to the SkyWalking console. If there is no data reported, we need to check the logs of SkyWalking Agent. You can view the error message in the agent/logs/ skywalk-api. log file.

Reference documentation

Skywalking official documentation

Apache SkyWalking Docker Files

Reporting Java application data through SkyWalking