preface

Nowadays, distributed and micro-services are prevalent. In the face of systems with more split services, if there is an anomaly online, it is necessary to quickly locate the abnormal service node. If there is still a traditional way to identify the abnormal service node, the efficiency is very low, because the various communications between services will make the location more complicated. Therefore, there is an urgent need for a distributed link tracking system to facilitate the rapid location of abnormal nodes, so as to deal with the problem. The more mainstream APM(Application Performance Management) system has SkyWalking, Zipkin, PinPoint, Cat and so on, here I first talk about SkyWalking, other follow-up to fill.

APM systems are of course more than just link tracing. They can also analyze applications and their running environment based on various performance metrics to quickly locate and resolve problems when they occur.

The body of the

1. SkyWalking profile

SkyWalking is an open source observability platform for collecting, analyzing, aggregating, and visualizing data from services and cloud native infrastructures such as databases, as well as providing an excellent visual interface. SkyWalking is also a modern APM designed for cloud-native, container-based distributed systems.

1.1 Common Terms

Services, service instances, and endpoints are often mentioned in SkyWalking, so here’s a look:

  • Service: Informally understood as an application; Take the order service API.
  • Service instance: Each node running independently in a service group is called an instance. A service can correspond to multiple service instances (clusters). For example, an order service can be clustered with several nodes, which are called service instances.
  • Endpoint: request service path, such as Http Url address or gRPC request address (gRPC defined service class + method name);

Popular understanding, as shown below:

1.2 Understanding architecture

SkyWalking is mainly divided into four parts: probe, platform backend, storage and UI, as shown below:

  • Probe: Designed to collect data and format it to SkyWalking’s specifications.
  • Back-end platform: aggregating, analyzing and streaming the collected data;
  • Storage: is the database, the collected data stored, convenient to view and analysis at any time; Mainstream databases include ElasticSearch, H2, MySQL, TiDB, and InfluxDB. You can use ElasticSearch to query for speed bar drops.
  • UI: Provides a Web interface, which can be very convenient to view and analyze data and display in various charts.

We know so much about theory temporarily, but it’s easier to understand it in practice.

2. Install

Here, Docker is used for installation, which is convenient and fast. If there are friends who do not know much about Docker, you can take a look at the Docker series I organized to share.

2.1 installation ElasticSearch

You need to install ElasticSearch in advance. Run the following command:

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 --restart always -e "discovery.type=single-node" -e ES_JAVA_OPTS = "- Xms64m - Xmx521m" elasticsearch: 6.7.2Copy the code

Command parsing:

  • -p 9200:9200 -p 9300:9300 Maps host ports 9200 and 9300 to the ports of the startup container.
  • -e “discovery.type=single-node”;
  • -e ES_JAVA_OPTS=” -xMS64m -XMx521m “Since the memory of my cloud server is relatively small, I set an environment variable ES_JAVA_OPTS to configure the memory used: the minimum memory is 64M, the maximum memory is 521M. Otherwise, the memory is insufficient and the startup cannot be started.
2.2 Installing the SkyWalking Background Server (Skywalk-OAP), run the following command:
docker run --name skywalking-oap --restart always -p 1234:1234 -p 11800:11800 -p 12800:12800 -d --link elasticsearch:elasticsearch -e SW_STORAGE=elasticsearch -e SW_STORAGE_ES_CLUSTER_NODES=elasticsearch:9200 Apache/skywalking - oap - server: 8.3.0 - es6Copy the code

Command parsing:

  • -p 1234:1234 -p 11800:11800 -p 12800:12800 Map host ports 1234, 11800, and 12800 to the ports of the startup container. The 11800 is for docking applications; 12800 is used to interface with SkyWalking’s UI data.
  • – link elasticsearch: elasticsearch represent step start elasticsearch network link, and can be accessed through container name corresponding service, pay attention to the container name and the same step;
  • -e SW_STORAGE= ElasticSearch Sets the storage mode of SkyWalking to ElasticSearch.
  • -e SW_STORAGE_ES_CLUSTER_NODES= ElasticSearch :9200 Specifies the address for elasticsearch.
2.3 Installing the SkyWalking UI (SkyWalking – UI), run the following command
docker run --name skywalking-ui --restart always -p 8080:8080 --link skywalking-oap:skywalking-oap -d -e SW_OAP_ADDRESS = skywalking - oap: 12800 apache/skywalking - UI: 6.6.0Copy the code

Command parsing:

  • -p 8080:8080 indicates the mapping between host port 8080 and container port 8080.
  • — Link Skywalk-OAP: Skywalk-OAP means that the skywalk-OAP network can be connected to the previous step, and the corresponding services can be accessed through the container name. Note that the container name is the same as the previous step.
  • -e SW_OAP_ADDRESS= Skywalking :12800 Sets the API address of the UI call, which is the back-end address of the last skywalking startup. The port number is 12800.

The environment is then installed if you can access the exposed port as follows:

Now that the environment is ready, the only thing left to do is project integration. Let’s test two apis.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * Skywalk-oap-server (SW_STORAGE= elasticSearch) can only connect to ElasticSearch6.

3. Project integration with SkyWalking

3.1 Install a SkyWalking command-line tool first

The command line tool will quickly generate a configuration file. Run the following command to install it:

Dotnet tool install -g skyapm.dotnet.cliCopy the code

Install it once. If it is already installed, you can skip this step.

3.2 Create a project and introduce the Skyapm.agent.aspnetcore package

This bag is specially designed for. NetCore developed probe.

3.3 Registering the Service and configuring environment variables
  • Register the service in the Startup file

  • Configuring environment Variables

    This is easy to test and can be configured directly in the launchsettings. json file of your project, but if you are in a release production environment, be sure to configure environment variables in the corresponding environment.

3.4 Running the SkyWalking Command to Generate the Configuration File

Run the following command in the root directory of the project

Dotnet skyapm config MySkyWalkingDemoTest 192.168.xxx.xxx:11800Copy the code
  • MySkyWalkingDemoTest is the service name;
  • XXX :11800 is the address of SkyWalking background service, which is the address set up by us in Step 2.2. Configure IP addresses based on actual needs.

After the command is executed, the Skyapm. json file will be generated in the root directory of the project. You can modify the configuration content as required.

By default, skyapm.json files are copied to the package directory whenever they are updated. To be on the safe side, right-click -> Properties and set the file to be copied always or if it is new.

3.5 Start the project and see the effect

SkyWalking embedded almost no code, ran the code directly, and now can track and monitor API services. The diagram below:

Take a look at the SkyWalking screen:

You can enter the tracking interface to see the specific request information:

Note: Conditional time pay attention to the time zone, set the time before; You can actually set the time zone when you start the setup environment.

Click on the tree request to see details:

3.6 Add an API service and test the call chain

Create a new project, SkyWalkingDemoTest22222, start with port 5100, otherwise unchanged; SkyWalking is not integrated here, if you need to monitor down, you can integrate with the above steps;

Then simply modify the interface of the SkyWalkingDemoTest project as follows:

Run SkyWalkingDemoTest22222 first and then SkyWalkingDemoTest. After the execution, you can go to the SkyWalking interface to see the tracking information as follows:

You can also see the effect in the topology:

Click the corresponding node to display the corresponding indicator data.

Reference Address:

  • Liverpoolfc.tv: skywalking.apache.org/
  • Open source: github.com/apache/skyw…
  • .NET probe: github.com/SkyAPM/SkyA…

Code case address: gitee.com/CodeZoe/mic…

conclusion

So much for the initial experience of SkyWalking, but for a complex system of communication between services, this makes it much clearer and easier to locate. In the next article, we will look at the metrics of the database and how to configure alarms. Watch Code Entertainment circle and learn with me.