文章目录
- 2.5.1.上传一个tomcat并解压
- 2.5.2.修改catalina.sh可以进行远程监控进程的配置
- 2.5.3.创建远程登录的账户和密码:jmxremote.access和 jmxremote.password
- 2.5.4.赋予上面两个文件权限:jmxremote.access和 jmxremote.password
- 2.5.4.启动应用程序tomcat
1.jconsole (jdk自带的一个界面工具)
JConsole工具是JDK自带的可视化监控工具。查看java应用程序的运行概况、监控堆信息、永久区使用情况、类加载情况等。
1.1.启动我们的一个springboot项目
1.2.启动jconsole
localhost:~
1.3.连接自己的应用程序
2.jvisualvm (也是jdk自带的可视化工具)
2.1.概述
1.既可以监控本地的进程,也可以监控远程进程;
2.2.打开方式
2.2.1.控台中执行:jvisualvm
localhost:~
回车即可
2.2.2.直接打开你自己的保存的jvisualvm 应用
2.3.界面介绍
打开jvisualvm
2.4本地连接
1.本地连接的方式不再赘述,启动之后自动的在左边就有了
2.5.远程连接:样例展示
2.5.1.上传一个tomcat并解压
[root@izwz91h49n3mj8r232gqwez apache-tomcat-8.5.50]# pwd
/opt/apache-tomcat-8.5.50
[root@izwz91h49n3mj8r232gqwez apache-tomcat-8.5.50]# ls -la
total 152
drwxr-xr-x 9 root root 4096 Mar 12 16:51 .
drwxr-xr-x. 8 root root 4096 Mar 12 16:51 ..
drwxr-x--- 2 root root 4096 Mar 12 16:51 bin
-rw-r----- 1 root root 19318 Dec 8 03:23 BUILDING.txt
drwx------ 2 root root 4096 Dec 8 03:23 conf
-rw-r----- 1 root root 5408 Dec 8 03:23 CONTRIBUTING.md
drwxr-x--- 2 root root 4096 Mar 12 16:51 lib
-rw-r----- 1 root root 57011 Dec 8 03:23 LICENSE
drwxr-x--- 2 root root 4096 Dec 8 03:19 logs
-rw-r----- 1 root root 1726 Dec 8 03:23 NOTICE
-rw-r----- 1 root root 3255 Dec 8 03:23 README.md
-rw-r----- 1 root root 7136 Dec 8 03:23 RELEASE-NOTES
-rw-r----- 1 root root 16262 Dec 8 03:23 RUNNING.txt
drwxr-x--- 2 root root 4096 Mar 12 16:51 temp
drwxr-x--- 7 root root 4096 Dec 8 03:21 webapps
drwxr-x--- 2 root root 4096 Dec 8 03:19 work
[root@izwz91h49n3mj8r232gqwez apache-t
2.5.2.修改catalina.sh可以进行远程监控进程的配置
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote - Djava.rmi.server.hostname=[阿里云机器的外网访问的ip] -Dcom.sun.management.jmxremote.port=[端口]
-Dcom.sun.management.jmxremote.ssl=false - Dcom.sun.management.jmxremote.authenticate=true - Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access - Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password"
配置解释
- Dcom.sun.management.jmxremote 开启远程连接
- Djava.rmi.server.hostname=[阿里云机器的外网访问的ip] 设置你得机器ip
- Dcom.sun.management.jmxremote.port=[端口] 设置你进程应用的端口
- Dcom.sun.management.jmxremote.ssl=false 是否开启远程的ssl安全连接
- Dcom.sun.management.jmxremote.authenticate=true 是否需要账户密码登录
- Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access 登录账户名所在的文件地址
- Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password 登录所有要的密码所在的文件地址
2.5.3.创建远程登录的账户和密码:jmxremote.access和 jmxremote.password
[root@izwz91h49n3mj8r232gqwez conf]# pwd
/opt/apache-tomcat-8.5.50/conf
[root@izwz91h49n3mj8r232gqwez conf]# ls -la
total 240
drwx------ 2 root root 4096 Mar 12 17:18 .
drwxr-xr-x 9 root root 4096 Mar 12 16:51 ..
-rw------- 1 root root 13548 Dec 8 03:23 catalina.policy
-rw------- 1 root root 7661 Dec 8 03:23 catalina.properties
-rw------- 1 root root 1338 Dec 8 03:23 context.xml
-rw------- 1 root root 1149 Dec 8 03:23 jaspic-providers.xml
-rw------- 1 root root 2313 Dec 8 03:23 jaspic-providers.xsd
-rw-r--r-- 1 root root 33 Mar 12 17:16 jmxremote.access
-rw-r--r-- 1 root root 37 Mar 12 17:18 jmxremote.password
-rw------- 1 root root 3916 Dec 8 03:23 logging.properties
-rw------- 1 root root 7513 Dec 8 03:23 server.xml
-rw------- 1 root root 2164 Dec 8 03:23 tomcat-users.xml
-rw------- 1 root root 2633 Dec 8 03:23 tomcat-users.xsd
-rw------- 1 root root 171482 Dec 8 03:23 web.xml
[root@izwz91h49n3mj8r232gqwez conf]#
jmxremote.access
guest readonly
manager readwrite
jmxremote.password
[root@izwz91h49n3mj8r232gqwez conf]# cat jmxremote.password
guest gxf6639848021@
manager gxf6639848021@
[root@izwz91h49n3mj8r232gqwez conf]#
2.5.4.赋予上面两个文件权限:jmxremote.access和 jmxremote.password
[root@izwz91h49n3mj8r232gqwez conf]# chmod 600 jmxremote.access
[root@izwz91h49n3mj8r232gqwez conf]# chmod 600 jmxremote.password
[root@izwz91h49n3mj8r232gqwez conf]#
备注
设置拥有者可读写,其他人不可读写执行
chmod 600 file (等价于 chmod u=rw,g=---,o=--- file 或 chmod u=rw,go-rwx file )
2.5.4.启动应用程序tomcat
[root@izwz91h49n3mj8r232gqwez bin]# pwd
/opt/apache-tomcat-8.5.50/bin
[root@izwz91h49n3mj8r232gqwez bin]# sh startup.sh
Using CATALINA_BASE: /opt/apache-tomcat-8.5.50
Using CATALINA_HOME: /opt/apache-tomcat-8.5.50
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.5.50/temp
Using JRE_HOME: /opt/jdk1.8.0_172
Using CLASSPATH: /opt/apache-tomcat-8.5.50/bin/bootstrap.jar:/opt/apache-tomcat-8.5.50/bin/tomcat-juli.jar
Tomcat started.
[root@izwz91h49n3mj8r232gqwez bin]#
3.arthas (阿里巴巴提供)
3.1.概述
1.Arthas 是Alibaba开源的Java诊断工具,深受开发者喜爱。
主要是针对已经启动的应用进程进行诊断分析
arthas在启动安装的时候,必须指定诊断的进程;
3.2.官网源码地址
https://github.com/alibaba/arthas
3.3.官网文档地址
https://alibaba.github.io/arthas/#
3.4.使用演示
3.4.1.我们首先启动一个业务程序-demo-jvm
源码地址
https://gitee.com/gaoxinfu_admin/demo-jdk/tree/master/demo-jvm
/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:49310,suspend=y,server=n -Xms200M -Xmx200M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=heap.hprof -javaagent:/Users/gaoxinfu/Library/Caches/IntelliJIdea2019.1/captureAgent/debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/tools.jar:/Users/gaoxinfu/demo-idea/demo-jdk/demo-jvm/target/classes:/Users/gaoxinfu/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.1.6.RELEASE/spring-boot-starter-web-2.1.6.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/boot/spring-boot-starter/2.1.6.RELEASE/spring-boot-starter-2.1.6.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/boot/spring-boot/2.1.6.RELEASE/spring-boot-2.1.6.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.1.6.RELEASE/spring-boot-autoconfigure-2.1.6.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.1.6.RELEASE/spring-boot-starter-logging-2.1.6.RELEASE.jar:/Users/gaoxinfu/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/Users/gaoxinfu/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/Users/gaoxinfu/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.11.2/log4j-to-slf4j-2.11.2.jar:/Users/gaoxinfu/.m2/repository/org/apache/logging/log4j/log4j-api/2.11.2/log4j-api-2.11.2.jar:/Users/gaoxinfu/.m2/repository/org/slf4j/jul-to-slf4j/1.7.26/jul-to-slf4j-1.7.26.jar:/Users/gaoxinfu/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar:/Users/gaoxinfu/.m2/repository/org/yaml/snakeyaml/1.23/snakeyaml-1.23.jar:/Users/gaoxinfu/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.1.6.RELEASE/spring-boot-starter-json-2.1.6.RELEASE.jar:/Users/gaoxinfu/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.9.9/jackson-databind-2.9.9.jar:/Users/gaoxinfu/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar:/Users/gaoxinfu/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.9/jackson-core-2.9.9.jar:/Users/gaoxinfu/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.9/jackson-datatype-jdk8-2.9.9.jar:/Users/gaoxinfu/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.9/jackson-datatype-jsr310-2.9.9.jar:/Users/gaoxinfu/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.9.9/jackson-module-parameter-names-2.9.9.jar:/Users/gaoxinfu/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.1.6.RELEASE/spring-boot-starter-tomcat-2.1.6.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.21/tomcat-embed-core-9.0.21.jar:/Users/gaoxinfu/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.21/tomcat-embed-el-9.0.21.jar:/Users/gaoxinfu/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.21/tomcat-embed-websocket-9.0.21.jar:/Users/gaoxinfu/.m2/repository/org/hibernate/validator/hibernate-validator/6.0.17.Final/hibernate-validator-6.0.17.Final.jar:/Users/gaoxinfu/.m2/repository/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final.jar:/Users/gaoxinfu/.m2/repository/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar:/Users/gaoxinfu/.m2/repository/com/fasterxml/classmate/1.4.0/classmate-1.4.0.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-web/5.1.8.RELEASE/spring-web-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-beans/5.1.8.RELEASE/spring-beans-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-webmvc/5.1.8.RELEASE/spring-webmvc-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-aop/5.1.8.RELEASE/spring-aop-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-context/5.1.8.RELEASE/spring-context-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-expression/5.1.8.RELEASE/spring-expression-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/slf4j/slf4j-api/1.7.26/slf4j-api-1.7.26.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-core/5.1.8.RELEASE/spring-core-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/org/springframework/spring-jcl/5.1.8.RELEASE/spring-jcl-5.1.8.RELEASE.jar:/Users/gaoxinfu/.m2/repository/asm/asm/3.3.1/asm-3.3.1.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" com.gaoxinfu.demo.jvm.DemoJvmApplication
Connected to the target VM, address: '127.0.0.1:49310', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2020-03-14 07:24:51.243 INFO 2102 --- [ main] c.gaoxinfu.demo.jvm.DemoJvmApplication : Starting DemoJvmApplication on localhost with PID 2102 (/Users/gaoxinfu/demo-idea/demo-jdk/demo-jvm/target/classes started by gaoxinfu in /Users/gaoxinfu/demo-idea/demo-jdk)
2020-03-14 07:24:51.249 INFO 2102 --- [ main] c.gaoxinfu.demo.jvm.DemoJvmApplication : No active profile set, falling back to default profiles: default
2020-03-14 07:24:53.582 INFO 2102 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-14 07:24:53.629 INFO 2102 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-14 07:24:53.629 INFO 2102 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2020-03-14 07:24:53.792 INFO 2102 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-14 07:24:53.797 INFO 2102 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2373 ms
2020-03-14 07:24:54.087 INFO 2102 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-14 07:24:54.377 INFO 2102 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-14 07:24:54.381 INFO 2102 --- [ main] c.gaoxinfu.demo.jvm.DemoJvmApplication : Started DemoJvmApplication in 3.664 seconds (JVM running for 4.363)
3.4.2.下载arthas
localhost:using gaoxinfu$ curl -O https://alibaba.github.io/arthas/arthas-boot.jar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 108k 100 108k 0 0 90024 0 0:00:01 0:00:01 --:--:-- 89951
localhost:using gaoxinfu$
localhost:using gaoxinfu$
localhost:using gaoxinfu$ ls -la|grep arthas
-rw-r--r-- 1 gaoxinfu staff 111090 3 14 07:12 arthas-boot.jar
3.4.2.启动arthas并指定诊断的应用程勋(我们这里就是上面刚刚启动的)
localhost:using gaoxinfu$ java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.1.7
[INFO] Found existing java process, please choose one and hit RETURN.
* [1]: 2101 org.jetbrains.jps.cmdline.Launcher
[2]: 2102 com.gaoxinfu.demo.jvm.DemoJvmApplication
[3]: 1452
2
[INFO] arthas home: /Users/gaoxinfu/.arthas/lib/3.1.7/arthas
[INFO] Try to attach process 2102
[INFO] Attach process 2102 success.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| | | || |\ \ | | | | | || | | |.-' |
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
wiki https://alibaba.github.io/arthas
tutorials https://alibaba.github.io/arthas/arthas-tutorials
version 3.1.7
pid 2102
time 2020-03-14 07:28:53
[arthas@2102]$
需要手动指定诊断的已经启动的应用程序
3.5.重要命令介绍
3.5.1.dashboard
[arthas@2102]$ dashboard
这里大家在操作的时候要注意下,如果你要退出当前的dashboar的命令界面,
输入 Q 或者 Ctrl+C 可以退出dashboard命令。
3.5.2.Thread
一目了然的了解系统的状态,哪些线程比较占cpu?他们到底在做什么?
[arthas@2102]$ thread 39
"nioEventLoopGroup-3-1" Id=39 RUNNABLE (in native)
at sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
at sun.nio.ch.KQueueArrayWrapper.poll(KQueueArrayWrapper.java:198)
at sun.nio.ch.KQueueSelectorImpl.doSelect(KQueueSelectorImpl.java:117)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked io.netty.channel.nio.SelectedSelectionKeySet@78a27bc8
- locked java.util.Collections$UnmodifiableSet@64c0b91c
- locked sun.nio.ch.KQueueSelectorImpl@344830e1
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:806)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:454)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Affect(row-cnt:0) cost in 13 ms.
[arthas@2102]$
4.Mat
5.Perfma
5.1.概述
1.在线的一个内存分析工具
5.2.官网