线上监控诊断神器arthas 桃扇骨 2024-03-26 14:42 21阅读 0赞 **目录** 什么是arthas 常用命令列表 1、dashboard仪表盘 2、heapdump dumpJAVA堆栈快照 3、jvm 4、thread 5、memory 官方文档 安装使用 1、云安装arthas 2、获取需要监控进程ID 3、运行arthas 4、进入仪表盘 5、其他命令使用查看官方文档 -------------------- ### 什么是arthas ### arthas是阿里巴巴开源的一款线上监控诊断产品,能够实时查看应用加载、内存、垃圾收集、线程等信息。可以在不修改代码的情况下,对线上应用进行诊断监控,大大提升异常排查效率。 ### ### ### 常用命令列表 ### #### 1、dashboard仪表盘 #### 进入仪表盘会显示当前 tomcat 的实时信息,如 HTTP 请求的 qps, rt, 错误数, 线程池信息等等。 ![6423a51255b4441992a726afff298e2f.png][] #### 2、heapdump dumpJAVA堆栈快照 #### dump 到指定文件 \[arthas@58205\]$ heapdump /tmp/dump.hprof Dumping heap to /tmp/dump.hprof... Heap dump file created #### 3、jvm #### 查看当前jvm信息 ![888ac58afea74f51bcc982e1264d5ec5.png][] #### 4、thread #### 查看线程信息 <table> <tbody> <tr> <td> <p>参数名称</p> </td> <td> <p>参数说明</p> </td> </tr> <tr> <td> <p>id</p> </td> <td> <p>线程 id</p> </td> </tr> <tr> <td> <p>[n:]</p> </td> <td> <p>指定最忙的前 N 个线程并打印堆栈</p> </td> </tr> <tr> <td> <p>[b]</p> </td> <td> <p>找出当前阻塞其他线程的线程</p> </td> </tr> <tr> <td> <p>[i <value>]</p> </td> <td> <p>指定 cpu 使用率统计的采样间隔,单位为毫秒,默认值为 200</p> </td> </tr> <tr> <td> <p>[--all]</p> </td> <td> <p>显示所有匹配的线程</p> </td> </tr> </tbody> </table> #### 5、memory #### 查看JVM内存信息 ![88bb08fc541c4e8eb5ef634ca82a3f2d.png][] #### 官方文档 #### [arthas][] ![ec1c5b89cc3343f3b1f73d8f118d2c1c.png][] ### 安装使用 ### #### 1、云安装arthas #### 命令: wget [https://arthas.aliyun.com/arthas-boot.jar][https_arthas.aliyun.com_arthas-boot.jar] ![0106884a88c94ab98e2b5d08651e2ba4.png][] #### 2、获取需要监控进程ID #### 命令:top -c ![f25137474dcb450b992c77d311a009b1.png][] 如图所示需要监控的进程ID为 1 #### 3、运行arthas #### 命令:java -jar [arthas-boot.jar][https_arthas.aliyun.com_arthas-boot.jar] 运行成功后键入进程ID 1 ![d04f3580836744979289f9eb2a1280b1.png][] 如图所示已经启动arthas并监控进程1的应用信息 #### 4、进入仪表盘 #### 命令:dashboard ![2321339192f744a8a462d1d693b97693.png][] 如图所示有进程运行的线程、内存、垃圾回收、运行时间等信息。如果应用存在内存泄露我们可以看到哪些线程占用内存最多,然后进入线程从而获取堆栈。 5、进入线程 命令: thread 线程ID \[arthas@1\]$ thread 812 ![9f9e83361ec64c829c441ae4f8052062.png][] 如图所示我们可以看到当前线程812的信息,在遇到内存泄露的情况下,这里就可以看到具体的代码逻辑。 #### 5、其他命令使用查看官方文档 #### [arthas][] **总结:线上监控诊断产品arthas入门容易、操作简单,特别适合线上应用查看加载、内存、垃圾回收GC、线程信息。其中的dashboard仪表盘非常容易监控和发现异常线程,极大的方便我们找出异常代码解决各种内存泄露等问题。** [6423a51255b4441992a726afff298e2f.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/d91f0a2781a74fd09e2af49a9ea4b33e.png [888ac58afea74f51bcc982e1264d5ec5.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/5de7f8eb9d6f476291776c6b37c12f70.png [88bb08fc541c4e8eb5ef634ca82a3f2d.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/c1aa9781f9b04179a5be9cf912e66a8c.png [arthas]: https://arthas.aliyun.com/ [ec1c5b89cc3343f3b1f73d8f118d2c1c.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/5f6f3684e226489d808a6f96dd0f362f.png [https_arthas.aliyun.com_arthas-boot.jar]: https://arthas.aliyun.com/arthas-boot.jar [0106884a88c94ab98e2b5d08651e2ba4.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/9930d016b8c04d3e8c4e02f3fb52e947.png [f25137474dcb450b992c77d311a009b1.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/aff8e928358e4afe87ee2641ace479c3.png [d04f3580836744979289f9eb2a1280b1.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/2e19cfd433e244a484e747261b22b7aa.png [2321339192f744a8a462d1d693b97693.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/684a1c36ad2f4cda9b4bb92dc616a4bd.png [9f9e83361ec64c829c441ae4f8052062.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/26/aec4a2f2b40149a2a3fe54e189570292.png
还没有评论,来说两句吧...