如何将分析器附加到 docker 进程

eat*_*ode 5 profiler docker

我在 Docker 容器中存在的作业服务器中面临内存泄漏问题。为了分析导致问题的原因,我需要将 jprofiler 或 yourkit 附加到 docker 容器进程。我不知道该怎么做。有人可以解释一下吗?

Von*_*onC 3

您可以尝试按照Andrew Liu的“配置 JProfiler 9.2 以分析在 Docker 容器中运行的应用程序” :

这需要使用以下命令来完成现有的 Dockerfile:

RUN wget http://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_9_2.tar.gz -P /tmp/ &&\
 tar -xzf /tmp/jprofiler_linux_9_2.tar.gz -C /usr/local &&\
 rm /tmp/jprofiler_linux_9_2.tar.gz

ENV JPAGENT_PATH="-agentpath:/usr/local/jprofiler9/bin/linux-x64/libjprofilerti.so=nowait"
EXPOSE 8849
Run Code Online (Sandbox Code Playgroud)

这将使您能够对正在运行的容器执行 bash:

docker exec -it [container-name] bash

cd /usr/local/jrofiler9/
bin/jpenable
Run Code Online (Sandbox Code Playgroud)

或者,如果您想在 Web 服务器启动时启用 JProfiler 代理并等待来自主机的 JProfiler GUI 连接,而不是将“ ENV JPAGENT_PATH="-agentpath:/usr/local/jprofiler9/bin/linux-x64/libjprofilerti.so=nowait"”放入 Dockerfile 中。将以下行添加到JAVA_OPTS. 对于 tomcat 来说,它将是CATALINA_OPTS.
注意:这config.xml将是放置 JProfiler 许可证密钥的位置。

JAVA_OPTS="$JAVA_OPTS -agentpath:/usr/local/jprofiler9/bin/linux-x64/libjprofilerti.so=port=8849,wait,config=/usr/local/jprofiler9/config.xml"
Run Code Online (Sandbox Code Playgroud)

现在您已经在 docker 容器端完成了。该容器已准备好连接到您的 JProfiler GUI。以下步骤需在主机上完成。

  1. 从https://www.ej-technologies.com/download/jprofiler/files下载 JProfiler 9.2并安装。
  2. Ctrl打开 JProfiler 并通过按+N或单击会话菜单中的“新会话”打开新会话。
  3. 在“会话类型”部分中选择“附加到已分析的 JVM(本地或远程)”。在“分析的 JVM 设置”部分中输入 IP 地址和 8849 作为分析端口。将其他设置保留为默认值。然后单击“确定”。