使用jattach 在host 节点查看容器jvm信息

jattach是基于hostspot attach api 指南编写的轻量all in one(jmap,jstack,jcmd,jinfo) 的工具
包含了以下命令

  • load 家在agent library
  • properties 加载系统属性
  • agentproperties 打印agent 属性信息
  • datadump 显示heap 以及thread 统计信息
  • threaddump dump 所有栈的追踪信息(类似jstack)
  • inspectheap heap 直方图(类似jmap -histo)
  • setflag 修改托管vm flag 信息
  • printflag 打印vm flag 信息
  • jcmd 执行jcmd 命令

安装

我们只需要jre,不需要jdk,同时支持容器的jvm 信息查看,官方提供了编译好的二进制文件,同时对于容器也支持了包

简单使用

  • 启动一个tomcat 容器
 
docker run -d tomcat
  • host 查看容器pid
ps -ef |grep tomcat
 

 

 

  • 查看jvm 信息
    host 机器
 
jattach 22408 jcmd Thread.print
Connected to remote JVM
Response code = 0
2019-12-13 01:51:23
Full thread dump OpenJDK 64-Bit Server VM (25.232-b09 mixed mode):
"Attach Listener" #46 daemon prio=9 os_prio=0 tid=0x00007f49e0001000 nid=0x37 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
"ajp-nio-8009-AsyncTimeout" #44 daemon prio=5 os_prio=0 tid=0x00007f4a106fd800 nid=0x36 waiting on condition [0x00007f49c913f000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
 at java.lang.Thread.sleep(Native Method)
 at org.apache.coyote.AbstractProtocol$AsyncTimeout.run(AbstractProtocol.java:1162)
 at java.lang.Thread.run(Thread.java:748)
"ajp-nio-8009-Acceptor-0" #43 daemon prio=5 os_prio=0 tid=0x00007f4a106fb800 nid=0x35 runnable [0x00007f49c9240000]
   java.lang.Thread.State: RUNNABLE
 at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
 at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
 at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
 - locked <0x00000000ee300f50> (a java.lang.Object)
 at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:482)
 at java.lang.Thread.run(Thread.java:748)
"ajp-nio-8009-ClientPoller-1" #42 daemon prio=5 os_prio=0 tid=0x00007f4a106fa000 nid=0x34 runnable [0x00007f49c9341000]
   java.lang.Thread.State: RUNNABLE
 at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
 at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
 at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
 at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
 - locked <0x00000000ec6cfbf0> (a sun.nio.ch.Util$3)
 - locked <0x00000000ec6cfbe0> (a java.util.Collections$UnmodifiableSet)
 - locked <0x00000000ec6cfac8> (a sun.nio.ch.EPollSelectorImpl)
 at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
 at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:825)
 at java.lang.Thread.run(Thread.java:748)
.....

说明

jattach 是一个很不错的工具,我们可以用来方便的分析记基于容器的jvm 应用性能,简单方便

参考资料

https://github.com/apangin/jattach

posted on 2019-12-13 09:56  荣锋亮  阅读(1643)  评论(0编辑  收藏  举报

导航