Experience SpringBoot+Skywalking in five minutes

SkyWalking is an application performance monitoring tool for distributed systems. It is designed for micro services, cloud native architecture and container based (Docker, K8s, Mesos) architecture. SkyWalking is an observational analysis platform and application performance management system. Provide integrated solutions for distributed tracking, service grid telemetry analysis, measurement aggregation and visualization. Support Java Net core, PHP, nodejs, golang, Lua language probe, and support the Service Mesh built by Envoy + Istio.

express setup

In this case, the data in skywalking is stored in elasticsearch, and elasticsearch7.0 needs to be installed in advance x. You can refer to this article( https://www.fangzhipeng.com/springboot/2020/06/01/sb-es.html )Of course, skywalking can store data in other databases, such as mysql and infludb.

Go to the official website to download the Apache skywalking installation package. In this case, the monitoring data needs to be stored in elasticsearch, so use Apache skywalking-apm-es7-6.6.0 tar. GZ this jar package, and elasticsearch7.0 needs to be installed x. Execute the following command to download skywalking

wget https://www.apache.org/dyn/closer.cgi/skywalking/6.6.0/apache-skywalking-apm-es7-6.6.0.tar.gz

Execute tar -zxvf apache-skywalking-apm-es7-6.6.0 tar. GZ, unzip apache-skywalking-apm-es7-6.6.0 tar. GZ, the extracted directory is as follows:

agent  bin  config  LICENSE  licenses  logs  mesh-buffer  NOTICE  oap-libs  README.txt  trace-buffer  webapp

The main directory structure is as follows:

  • The bin directory stores the startup script, including oapservice sh,webappService.sh and other startup scripts
  • config is the configuration of oap service, including an application What about the configuration of YML
  • Agent is the agent of skywalking, which is generally used to collect business system logs
  • The webapp directory is the configuration of the UI interface service of the skywalking front end

The overall architecture is as follows:

In the whole skywalking system, there are four roles:

  • skywalking agent is bound with the business system and is responsible for collecting various monitoring data
  • Skywalking oapservice is responsible for processing monitoring data, such as accepting the monitoring data of skywalking agent and storing it in the database (elasticsearch is used in this case); Accept the front-end request of skywalking webapp, query the data from the database and return the data to the front-end. Skywalking oapservices usually exist in the form of clusters.
  • skywalking webapp, the front-end interface, is used to display data.
  • The database used to store monitoring data, such as mysql, elasticsearch, etc.

Start Skywalking oapservice

Modify the configuration file of oapservice, and in the config directory, click application In the YML file.

cluster:
  standalone:
storage:
 elasticsearch7:
    nameSpace: ${SW_NAMESPACE:"my-application"}
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
    protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    trustStorePath: ${SW_SW_STORAGE_ES_SSL_JKS_PATH:"../es_keystore.jks"}
    trustStorePass: ${SW_SW_STORAGE_ES_SSL_JKS_PASS:""}
    user: ${SW_ES_USER:""}
    password: ${SW_ES_PASSWORD:""}
    indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
    indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
    recordDataTTL: ${SW_STORAGE_ES_RECORD_DATA_TTL:7} 
    otherMetricsDataTTL: ${SW_STORAGE_ES_OTHER_METRIC_DATA_TTL:45} 
    monthMetricsDataTTL: ${SW_STORAGE_ES_MONTH_METRIC_DATA_TTL:18} 
    bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000}
    flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10}
    concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} 
    resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
    metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
  • cluster.standalone clusters exist in the form of monomers
  • storage.elasticsearch7 is used for storage X version.
  • storage.elasticsearch7.clusterNodes fill in elasticsearch

Execute the startup script of oapService in the bin directory

sh oapService.sh

The oapService service exposes two ports: Port 11800 for collecting monitoring data and port 12800 for receiving front-end requests.

Start skywalking webapp

skywalking webapp is a front-end interface for displaying data. Modify webapp in the webapp directory 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
  • server.port is the startup port of webapp
  • collector.ribbon.listOfServers fill in the port of Skywalking oapservice.

Execute the webappService startup command under the bin directory:

sh webappService.sh

spring boot project integration

Copy the agent directory to the machine where the spring boot project is deployed, and modify the agent configuration in agent / config / agent config:

agent.service_name=${SW_AGENT_NAME:my-skywalking}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}

# Logging file_name
logging.file_name=${SW_LOGGING_FILE_NAME:skywalking-api.log}

# Logging level
logging.level=${SW_LOGGING_LEVEL:DEBUG}
  • agent.service_name and springboot application Name is OK, or you can choose a name at will, but don't duplicate the name with other applications.
  • collector.backend_service fill in the address of oapService and port 11800.

Start the springboot project in the form of javaagent:

java -javaagent:/root/skywalking/apache-skywalking-apm-bin-es7/agent/skywalking-agent.jar -jar boot-es-0.0.1-SNAPSHOT.jar
  • -javaagent:/root/skywalking/apache-skywalking-apm-bin-es7/agent/skywalking-agent.jar, specify the directory of javaagent, skywalking agent The absolute path of the jar on the machine.
  • boot-es-0.0.1-SNAPSHOT. The source code download address of jar is https://github.com/forezp/distributed-lab/tree/master/boot-es

Simple test

In boot-es-0.0.1-snapshot The following interfaces are called on the machine started by jar:

curl localhost:8500/testInsert
curl localhost:8500/testGetAll

Visit skywalking webapp address on the browse, for example, skywalking webapp is installed locally, that is, access to localhost:8080, the home page is displayed as follows (if the data is not displayed, try to empty cache retry, the front end does not seem to be awesome), and display some data of the interface request:

The topology diagram is as follows:

Details of interface data call are as follows:

Source download

https://github.com/forezp/distributed-lab/tree/master/boot-es

Added by trock74 on Thu, 06 Jan 2022 11:18:43 +0200