diff --git a/site/src/site/sphinx/_include_html/arthas-tutorials.html b/site/src/site/sphinx/_include_html/arthas-tutorials.html index de62cee87..95cff06fd 100644 --- a/site/src/site/sphinx/_include_html/arthas-tutorials.html +++ b/site/src/site/sphinx/_include_html/arthas-tutorials.html @@ -479,6 +479,18 @@ cn: "command-vmoption-cn", } }, + { + id: "command-vmtool", + type: "COMMAND-SYSTEM", + names: { + en: "vmtool", + cn: "vmtool", + }, + ids: { + en: "command-vmtool-en", + cn: "command-vmtool-cn", + } + }, { id: "command-perfcounter", type: "COMMAND-SYSTEM", diff --git a/tutorials/katacoda/command-vmtool-cn/arthas-boot.md b/tutorials/katacoda/command-vmtool-cn/arthas-boot.md new file mode 100644 index 000000000..da13e133e --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动: + +`wget https://arthas.aliyun.com/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot`是`Arthas`的启动程序,它启动后,会列出所有的Java进程,用户可以选择需要诊断的目标进程。 + +选择第一个进程,输入 `1`{{execute T2}} ,再`Enter/回车`: + +Attach成功之后,会打印Arthas LOGO。输入 `help`{{execute T2}} 可以获取到更多的帮助信息。 + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/command-vmtool-cn/finish.md b/tutorials/katacoda/command-vmtool-cn/finish.md new file mode 100644 index 000000000..14f8e9d36 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/finish.md @@ -0,0 +1,11 @@ + +通过本教程基本掌握了Arthas vmtool 命令。如果有更多的技巧或者使用疑问,欢迎在Issue里提出。 + +* Issues: https://github.com/alibaba/arthas/issues +* 文档: https://arthas.aliyun.com/doc + +如果您在使用Arthas,请让我们知道。您的使用对我们非常重要:[查看](https://github.com/alibaba/arthas/issues/111) + +欢迎关注公众号,获取Arthas项目的信息、源码分析、案例实践。 + +![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg) diff --git a/tutorials/katacoda/command-vmtool-cn/index.json b/tutorials/katacoda/command-vmtool-cn/index.json new file mode 100644 index 000000000..fa7fa03ca --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/index.json @@ -0,0 +1,57 @@ +{ + "title": "Arthas vmtool 命令", + "description": "Arthas vmtool 命令", + "difficulty": "精通者", + "time": "10分钟", + "details": { + "steps": [ + { + "title": "Start demo", + "text": "start-demo.md" + }, + { + "title": "Start arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool-spring.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool-classloader.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool-gc.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "openjdk:15", + "environmentsprotocol": "http" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-cn/intro.md b/tutorials/katacoda/command-vmtool-cn/intro.md new file mode 100644 index 000000000..d632440c1 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/intro.md @@ -0,0 +1,12 @@ + + + +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。 + + +本教程会以一个普通的Spring Boot应用为例,演示使用`vmtool`命令从JVM内部查找对象。 + +* Github: https://github.com/alibaba/arthas +* 文档: https://arthas.aliyun.com/doc/ diff --git a/tutorials/katacoda/command-vmtool-cn/start-demo.md b/tutorials/katacoda/command-vmtool-cn/start-demo.md new file mode 100644 index 000000000..59be66ea6 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/start-demo.md @@ -0,0 +1,14 @@ + + + + +下载`demo-arthas-spring-boot.jar`,再用`java -jar`命令启动: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot`是一个很简单的spring boot应用,源代码:[查看](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +启动之后,可以访问80端口: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool-classloader.md b/tutorials/katacoda/command-vmtool-cn/vmtool-classloader.md new file mode 100644 index 000000000..997ec1011 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool-classloader.md @@ -0,0 +1,32 @@ + + + +### 指定 classloader name + +```bash +vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext +``` + + +### 指定 classloader hash + +可以通过`sc`命令查找到加载class的 classloader。 + +```bash +$ sc -d org.springframework.context.ApplicationContext + class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext + code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/ + name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext +... + class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2 + +-sun.misc.Launcher$AppClassLoader@75b84c92 + +-sun.misc.Launcher$ExtClassLoader@4f023edb + classLoaderHash 19469ea2 +``` + +然后用`-c`/`--classloader` 参数指定: + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext +``` + diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool-gc.md b/tutorials/katacoda/command-vmtool-cn/vmtool-gc.md new file mode 100644 index 000000000..ac9da5780 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool-gc.md @@ -0,0 +1,6 @@ + +### 强制GC + +```bash +vmtool --action forceGc +``` diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool-spring.md b/tutorials/katacoda/command-vmtool-cn/vmtool-spring.md new file mode 100644 index 000000000..8c37925e8 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool-spring.md @@ -0,0 +1,55 @@ +下面使用`vmtool`命令查找spring里的对象。 + +### 查找spring context + +```bash +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext +@ApplicationContext[][ + @AnnotationConfigEmbeddedWebApplicationContext[org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12028586: startup date [Thu May 13 16:08:38 UTC 2021]; root of context hierarchy], +] +``` + +### 指定返回结果展开层数 + +> `getInstances` action返回结果绑定到`instances`变量上,它是数组。 + +> 通过 `-x`/`--expand` 参数可以指定结果的展开层次,默认值是1。 + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext -x 2 +``` + +### 执行表达式 + +> `getInstances` action返回结果绑定到`instances`变量上,它是数组。可以通过`--express`参数执行指定的表达式。 + +查找所有的spring beans名字: + +```bash +vmtool --action getInstances --className org.springframework.context.ApplicationContext --express 'instances[0].getBeanDefinitionNames()' +``` + +调用`userController.findUserById(1)`函数: + +``` +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext --express 'instances[0].getBean("userController").findUserById(1)' +@User[ + id=@Integer[1], + name=@String[name1], +] +``` + +### 查找所有的spring mapping对象 + +```bash +$ vmtool --action getInstances --className org.springframework.web.servlet.HandlerMapping +@HandlerMapping[][ + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@5d3819c8], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@11d509ba], + @RequestMappingHandlerMapping[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@56a5f2e3], + @WelcomePageHandlerMapping[org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WelcomePageHandlerMapping@4c0a4ed3], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@51e1f8c3], + @BeanNameUrlHandlerMapping[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@68c0a39c], + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@110b768d], +] +``` diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool.md b/tutorials/katacoda/command-vmtool-cn/vmtool.md new file mode 100644 index 000000000..24a2f5fe8 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool.md @@ -0,0 +1,35 @@ + + +下面使用`vmtool`命令查找jvm对象。 + + +### 查找jvm里的字符串对象 + +```bash +$ vmtool --action getInstances --className java.lang.String +@String[][ + @String[Sorry, deque too big], + @String[head=%d tail=%d capacity=%d%n], + @String[elements=%s%n], + @String[sun/nio/ch/IOVecWrapper], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[sun/nio/ch/AllocatedNativeObject], + @String[sun/nio/ch/NativeObject], + @String[sun/nio/ch/IOVecWrapper$Deallocator], + @String[Java_sun_nio_ch_FileDispatcherImpl_writev0], +] +``` + +### limit参数 + +> 通过 `--limit`参数,可以限制返回值数量,避免获取超大数据时对JVM造成压力。默认值是10。 + +所以上面的命令实际上等值于: + +```bash +vmtool --action getInstances --className java.lang.String --limit 10 +``` + +如果设置`--limit`为负数,则遍历所有对象。 + diff --git a/tutorials/katacoda/command-vmtool-en/arthas-boot.md b/tutorials/katacoda/command-vmtool-en/arthas-boot.md new file mode 100644 index 000000000..0f2cd22ac --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command: + +`wget https://arthas.aliyun.com/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed. + +Select the first process, type `1`{{execute T2}} ,then type `Enter`: + +After the Attach is successful, Arthas LOGO is printed. Enter `help`{{execute T2}} for more help. + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/command-vmtool-en/finish.md b/tutorials/katacoda/command-vmtool-en/finish.md new file mode 100644 index 000000000..e95ec3feb --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/finish.md @@ -0,0 +1,7 @@ + +The `vmtool Tutorial` demonstrates the usage of `vmtool`. If you have more tips or questions, please feel free to tell or ask in Issue. + +* Issues: https://github.com/alibaba/arthas/issues +* Documentation: https://arthas.aliyun.com/doc/en + +If you are using Arthas, please let us know that. Your use is very important to us: [View](https://github.com/alibaba/arthas/issues/111) diff --git a/tutorials/katacoda/command-vmtool-en/index.json b/tutorials/katacoda/command-vmtool-en/index.json new file mode 100644 index 000000000..e314aafeb --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/index.json @@ -0,0 +1,57 @@ +{ + "title": "Arthas vmtool command", + "description": "Arthas vmtool command", + "difficulty": "master", + "time": "10 minutes", + "details": { + "steps": [ + { + "title": "Start demo", + "text": "start-demo.md" + }, + { + "title": "Start arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool-spring.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool-classloader.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool-gc.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "openjdk:15", + "environmentsprotocol": "http" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-en/intro.md b/tutorials/katacoda/command-vmtool-en/intro.md new file mode 100644 index 000000000..1b54d431c --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/intro.md @@ -0,0 +1,12 @@ + + + +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers. + + +This tutorial takes a simple application as an example to demonstrate the the usage of `vmtool`. + +* Github: https://github.com/alibaba/arthas +* Docs: https://arthas.aliyun.com/doc/en diff --git a/tutorials/katacoda/command-vmtool-en/start-demo.md b/tutorials/katacoda/command-vmtool-en/start-demo.md new file mode 100644 index 000000000..4915b847a --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/start-demo.md @@ -0,0 +1,14 @@ + + + + +Download `demo-arthas-spring-boot.jar`, and start with `java -jar` command: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot` is a simple Spring Boot demo, the source code here: [View](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +After booting, access port 80: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-en/vmtool-classloader.md b/tutorials/katacoda/command-vmtool-en/vmtool-classloader.md new file mode 100644 index 000000000..01eab4f72 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool-classloader.md @@ -0,0 +1,28 @@ +### Specify classloader name + +```bash +vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext +``` + + +### Specify classloader hash + +The classloader that loads the class can be found through the `sc` command. + +```bash +$ sc -d org.springframework.context.ApplicationContext + class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext + code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/ + name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext +... + class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2 + +-sun.misc.Launcher$AppClassLoader@75b84c92 + +-sun.misc.Launcher$ExtClassLoader@4f023edb + classLoaderHash 19469ea2 +``` + +Then use the `-c`/`--classloader` parameter to specify: + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext +``` \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-en/vmtool-gc.md b/tutorials/katacoda/command-vmtool-en/vmtool-gc.md new file mode 100644 index 000000000..b2d98069a --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool-gc.md @@ -0,0 +1,6 @@ + +### forceGc + +```bash +vmtool --action forceGc +``` diff --git a/tutorials/katacoda/command-vmtool-en/vmtool-spring.md b/tutorials/katacoda/command-vmtool-en/vmtool-spring.md new file mode 100644 index 000000000..dc0531e2a --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool-spring.md @@ -0,0 +1,55 @@ +Next, use the `vmtool` command to find objects in spring. + +### Find spring context + +```bash +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext +@ApplicationContext[][ + @AnnotationConfigEmbeddedWebApplicationContext[org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12028586: startup date [Thu May 13 16:08:38 UTC 2021]; root of context hierarchy], +] +``` + +### Specify the number of expanded layers of returned results + +> The return result of the `getInstances` action is bound to the `instances` variable, which is an array. + +> The expansion level of the result can be specified by the `-x`/`--expand` parameter, the default value is 1. + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext -x 2 +``` + +### Execute expression + +> The return result of the `getInstances` action is bound to the `instances` variable, which is an array. The specified expression can be executed through the `--express` parameter. + +Find the names of all spring beans: + +```bash +vmtool --action getInstances --className org.springframework.context.ApplicationContext --express'instances[0].getBeanDefinitionNames()' +``` + +Call the `userController.findUserById(1)` function: + +``` +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext --express'instances[0].getBean("userController").findUserById(1)' +@User[ + id=@Integer[1], + name=@String[name1], +] +``` + +### Find all spring mapping objects + +```bash +$ vmtool --action getInstances --className org.springframework.web.servlet.HandlerMapping +@HandlerMapping[][ + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@5d3819c8], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@11d509ba], + @RequestMappingHandlerMapping[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@56a5f2e3], + @WelcomePageHandlerMapping[org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WelcomePageHandlerMapping@4c0a4ed3], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@51e1f8c3], + @BeanNameUrlHandlerMapping[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@68c0a39c], + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@110b768d], +] +``` diff --git a/tutorials/katacoda/command-vmtool-en/vmtool.md b/tutorials/katacoda/command-vmtool-en/vmtool.md new file mode 100644 index 000000000..e230a1b89 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool.md @@ -0,0 +1,35 @@ + + + +Use the `vmtool` command to find the jvm object. + + +### Find string objects in jvm + +```bash +$ vmtool --action getInstances --className java.lang.String +@String[][ + @String[Sorry, deque too big], + @String[head=%d tail=%d capacity=%d%n], + @String[elements=%s%n], + @String[sun/nio/ch/IOVecWrapper], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[sun/nio/ch/AllocatedNativeObject], + @String[sun/nio/ch/NativeObject], + @String[sun/nio/ch/IOVecWrapper$Deallocator], + @String[Java_sun_nio_ch_FileDispatcherImpl_writev0], +] +``` + +### limit parameter + +> Through the `--limit` parameter, you can limit the number of return values to avoid pressure on the JVM when obtaining large data. The default value is 10. + +So the above command is actually equivalent to: + +```bash +vmtool --action getInstances --className java.lang.String --limit 10 +``` + +If you set `--limit` to a negative number, all objects are traversed.