Various methods used by Arthas

Head picture.png

Author | Montos (an introverter who crawls on the back-end road)
Source | Alibaba Cloud Native Official Account

Arthas is Alibaba's open source Java diagnostic tool. Allows us to troubleshoot project problems online. In addition to knowing its existence, we also need to know how we install and use it in order to improve the efficiency of our daily development and solving BUG.

An Introduction

Option 1: Run directly locally

Often the simplest method is actually the most effective. It is a runnable program in itself, so we can run it directly.

  • We can download the corresponding jar directly through the official website, then run the jar and execute the corresponding command.

  • The command is as follows:
java -jar arthas-boot.jar [option]
  • The demonstration is as follows:

1.jpeg

Option 2: Web Console implementation

We can execute the program instead of entering ssh every time, we can also access it through the web. Through the introduction of arthas Web Console on the official website, we can understand the general idea of ​​building.

  • By downloading arthas-tunnel-server. We can get the corresponding arthas server side. You can run it directly after downloading (I run it directly on ECS).

2.jpeg

  • Start arthas-boot corresponding to the client. And append the address of the server through the startup parameters (I run it locally).

3.jpeg

  • Select the corresponding process to attach, the corresponding agent-id will appear, and then fill it in the corresponding server-side http page.

4.jpeg

5.jpeg

  • Finally, we can operate on the server side, that is, the implementation of the Web Console is complete.

6.jpeg

Option 3: Project dependency

Projects built based on Spring are directly added to dependencies (corresponding environment support is required, for example, tools.jar cannot be missing).

  • The SpringBoot project depends on:
<dependency>
            <groupId>com.taobao.arthas</groupId>
            <artifactId>arthas-spring-boot-starter</artifactId>
            <version>${arthas.version}</version>
        </dependency>
  • Non-SpringBoot project dependencies:
<dependency>
            <groupId>com.taobao.arthas</groupId>
            <artifactId>arthas-agent-attach</artifactId>
            <version>${arthas.version}</version>
        </dependency>
        <dependency>
            <groupId>com.taobao.arthas</groupId>
            <artifactId>arthas-packaging</artifactId>
            <version>${arthas.version}</version>
        </dependency>
  • After the local project is started, you can directly access:
http://127.0.0.1:3658/
  • Of course, it can also be combined with the Web Console introduced above. For example, the corresponding configuration information is added to the configuration file:
arthas.agent-id=qwejqjnnnunnq
arthas.tunnel-server=ws://server地址:7777/ws
  • The demonstration is as follows:

7.jpeg

8.jpeg

9.jpeg

The above steps are to start the tunnel-server first, and then configure the local configuration to connect to the tunnel-server. Then enter the configured Id to complete the corresponding debugging.

Option 4: Container Configuration

Based on the docker configuration, there are not a few companies that currently use container services. For container services, this is also applicable. After downloading the jar, perform an ADD operation, or build a Dockerfile every time, a corresponding image file containing arthas will be generated.

Here is an introduction to building through Dockerfile:

FROM openjdk:8-jdk-alpine
ADD target/*.jar app.jar
# copy arthas
COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
MAINTAINER Montos [email protected]

The above is done by building a Dockerfile. Here, we will post the image file directly. Here we will copy the files in current arthas to the corresponding container. Then we can enter the execution through exec -it. The steps are similar to the method one.

to sum up

Through the above introduction, in fact, I would prefer to use the web access method for the following reasons:

  • When the service is directly deployed on the server or ECS cloud server. We can run directly on the corresponding client side, but how do we get to the server where each service is located? Through the springboard? So is it possible that the corresponding server may be affected when we operate, and it is definitely not possible to connect directly to the server.

  • The service is in the case of the running pod. At this time, the impact of letting you connect to the service is much smaller than the above situation. If the impact occurs, it will only affect the currently running pod. But if you want to directly connect to the pod, you need to map the corresponding pod port to the corresponding host, and then provide an external link to access ecs. This will make the port that needs to be mapped out each time the pod needs certain rules, which undoubtedly increases the operation and maintenance and other tasks, and the operation also consumes the current resources (to access the page, etc., use the http interface request, if you connect via ws, Reduce the consumption of 7 layers).

  • If the above method is used, then we can run the server on another machine. We will connect to the corresponding client by accessing the server every time we visit. At the same time, the corresponding agent-id can be specified, and we can do it every pod When the client is running, specify the current agent-id to bind it to the current pod so that we can connect through the server.

Of course, the benevolent see the benevolent and the wise see the wisdom in the above viewpoints. The above introduces several methods of deployment and operation of arthas. Enterprises can choose the appropriate deployment to solve them according to the current project architecture. Why is it needed? ? ? ? Just because it can help development and solve problems, there is no need to send back and forth versions!

Guess you like

Origin blog.51cto.com/13778063/2621283