How to integrate docker based project with skywalking agent

Time:2021-8-25

Introduction to skywalking

Skywalking is an open source application performance monitoring system, including index monitoring, distributed tracking and distributed system performance diagnosis

Skywalking official Chinese translation document

https://skyapm.github.io/document-cn-translation-of-skywalking/

How to quickly build skywalking

https://github.com/apache/skywalking-docker

How does the project integrate skywalking

1. Download skywalking agent

https://archive.apache.org/dist/skywalking/

The extracted directory is as follows
How to integrate docker based project with skywalking agent

2. Configure skywalking probe for our project

The shape is as follows

java -javaagent:D:apache-skywalking-apm-es7-8.4.0/apache-skywalking-apm-bin-es7/agentskywalking-agent.jar -Dskywalking.agent.service_ Name = display name of current project in skywalking - dskywalking.collector.backend_ service=xxxx:11800 -jar spring-demo-0.0.1-SNAPSHOT.jar

In fact, the official also provides documents to tell us how to configure, as shown in the figure below
How to integrate docker based project with skywalking agent
For more detailed configuration information, you can view the following links
https://github.com/apache/skywalking/blob/master/docs/en/setup/service-agent/java-agent/README.md

Through the above steps, the project can be integrated with skywalking. However, some small partners report that in the docker environment, they don’t know how to use skywalking agent to bury points. Next, let’s introduce how to integrate docker based deployment projects with skywalking agent

Thinking point: how can skywalking agent be used in projects in docker?

Everyone may understand the truth, that is, put skywalking agent and project into the same docker container. Based on this theory, the following two schemes are derived

Scheme 1: integrate the entire agent folder of skywalking agent into the project to be buried

The shape is shown in the figure below:

How to integrate docker based project with skywalking agent
Then modify the dockerfile file of the project. The modified content is as follows

FROM adoptopenjdk/openjdk8
VOLUME /tmp
COPY localtime /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone
COPY target/spring-demo-*.jar app.jar
COPY agent /usr/local/agent
ENTRYPOINT [ "sh", "-c", "java  -javaagent:/usr/local/agent/skywalking-agent.jar -Dskywalking.agent.service_name=spring-demo -Dskywalking.collector.backend_service=192.168.1.2:11800 -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

The main of the core is the following two sentences

COPY agent /usr/local/agent
ENTRYPOINT [ "sh", "-c", "java  -javaagent:/usr/local/agent/skywalking-agent.jar -Dskywalking.agent.service_name=spring-demo -Dskywalking.collector.backend_service=192.168.1.2:11800 -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

Copy the agent folder in the project to the / usr / local / agent folder in the container, and then the following operations are the same as using skwalking agent in a normal environment

After integration, see the figure below
How to integrate docker based project with skywalking agent

Scheme 2: when we build the basic image, skywalking agent is also added

For example, when we build the JDK basic image running in Java, we add skywalking agent
How to integrate docker based project with skywalking agent
The dockerfile contents are as follows

FROM adoptopenjdk/openjdk8
VOLUME /tmp
#ENV JAVA_OPTS="-Dcom.sun.management.jmxremote.port=39083 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
ENV JAVA_OPTS=""
ENV SKYWALKING_AGENT_SERVICE_NAME=""
ENV SKYWALKING_COLLECTOR_BACKEND_SERVICE=""
COPY localtime /etc/localtime
COPY agent /usr/local/agent
RUN echo "Asia/Shanghai" > /etc/timezone

ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -javaagent:/usr/local/agent/skywalking-agent.jar -Dskywalking.agent.service_name=$SKYWALKING_AGENT_SERVICE_NAME -Dskywalking.collector.backend_service=$SKYWALKING_COLLECTOR_BACKEND_SERVICE -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

Then build the basic image through docker build – t image name or docker compose build

The basic image built in this example is openjdk8 trace agent.

Here are several parameter descriptions: skywalking_ AGENT_ SERVICE_ Name and skywarming_ COLLECTOR_ BACKEND_ Service is an environment variable. You can specify specific environment variable values in docker-compose.yml file or k8s file. Take docker-compose.yml as an example

The configuration is as follows

version: '3.1'
services:
  spring-demo:
    restart: always
    image: 192.168.1.3:5002/demo/spring-demo:dev
    container_name: spring-demo
    network_mode: bridge
    ports:
     - "8085:8080"
    environment:
     - SKYWALKING_AGENT_SERVICE_NAME=spring-demo-test
     - SKYWALKING_COLLECTOR_BACKEND_SERVICE=192.168.1.2:11800

secondly

ONBUILD COPY app.jar app.jar

When Maven is built, we uniformly name the business jars as app.jar, so the first app.jar is the jar of our business project, and the second jar is the jar running in the docker container. In this way, we only need to write this in the dockerfile of the business

FROM 192.168.1.3:5002/dev/openjdk8-trace-agent

The example after integration is shown in the figure below
How to integrate docker based project with skywalking agent

summary

Distributed link tracking is basically a required option in microservices. At present, in addition to skywalking, there are also pinpoint, Jaeger, Zipkin, cat, etc. for open source link tracking on the market. If you are interested, you can learn about it. In addition, this article provides that using skywalking agent in docker container may not be the best solution, so let’s take it as a reference

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]