• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

排查Docker容器Java程序CPU过高问题以和处理方法

武飞扬头像
LoyalWei1220
帮助1

因为Docker里java程序运行环境是用的jre,没有top和jstack命令,所以要在容器里安装top和jattach,来查看和导出线程信息。

系统:Debian10

镜像:openjdk:8u275-jre-slim-buster

容器ID:99abe55a98dc


一.安装top:

    1.进入容器:
 

docker exec -it 99abe55a98dc /bin/bash

    2.因为官方镜像地址太慢,所以修改源地址:https://developer.aliyun.com/mirror/
    点击Debian,进入https://developer.aliyun.com/mirror/debian?spm=a2c6h.13651102.0.0.3e221b11I0yNcy
  选择Debian10配置的配置,>指令覆盖文件原内容并重新输入内容,若文件不存在则创建文件 >>指令代表追加 ,xshell直接一起执行,有的可能会报tmp文件夹没有执行权限,chmod 777即可

  1.  
        echo "deb https://mirrors.aliyun.com/debian/ buster main non-free contrib" > /etc/apt/sources.list
  2.  
        echo "deb-src https://mirrors.aliyun.com/debian/ buster main non-free contrib" >> /etc/apt/sources.list
  3.  
        echo "deb https://mirrors.aliyun.com/debian-security buster/updates main" >> /etc/apt/sources.list
  4.  
        echo "deb-src https://mirrors.aliyun.com/debian-security buster/updates main" >> /etc/apt/sources.list
  5.  
        echo "deb https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> /etc/apt/sources.list
  6.  
        echo "deb-src https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> /etc/apt/sources.list
  7.  
        echo "deb https://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> /etc/apt/sources.list
  8.  
        echo "deb-src https://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> /etc/apt/sources.list

    3.更新源
    

apt-get update

    4.安装
  

 apt-get install procps

    5.查看java进程里面占用资源最多的线程(docker中java程序pid一般是1,也可能是其他,和Dockerfile里的ENTRYPOINT启动方式有关,可以top先看一下COMMAND列是java的行)
  

  top -Hp 1

    6.上述命令得到高的线程,比如是8,转pid为十六进制,为查找文件使用
  

  printf "%x\n" 8


二.安装jattach,详情访问:GitHub - jattach/jattach: JVM Dynamic Attach utility

    通过动态附加机制向JVM进程发送命令的实用程序。一体机jmap jstack jcmd jinfo功能在一个单一的小程序。不需要安装JDK,只使用JRE。支持Linux容器。

    1.下载jattach
    https://github.com/apangin/jattach/releases
    放到服务器上,比如:/usr/local

    2.复制jattach到容器内部
 

 docker cp /usr/local/jattach 99abe55a98dc:/usr/bin

    3.进入容器
    

docker exec -it 99abe55a98dc /bin/bash

    4.进入容器,将jattach改为可执行状态
    

chmod  x /usr/bin/jattach

    5.把线程详情导出到文件里查看
 

   jattach 1 threaddump > /opt/threaddump.hprof

    6.在文件查找某个线程信息,比如0x8
  

 grep -20  --color=auto 0x8 /opt/threaddump.hprof 


    
    7.也可以退出容器后,执行命令,导出到容器外看
  

 docker cp 99abe55a98dc:/opt/threaddump.hprof /usr/local


    
    
    


 

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgcgkfk
系列文章
更多 icon
同类精品
更多 icon
继续加载