本文详细介绍了将 Arthas 集成到 Apache DolphinScheduler 中以实现 API 调用的实时监控。 Arthas是一款功能强大的Java诊断工具,可以帮助开发者检查运行时状态、识别性能瓶颈、跟踪方法调用。在DolphinScheduler中嵌入Arthas可以在任务调度期间捕获关键调用信息,从而能够及时检测和解决问题,从而提高系统稳定性。在这里,我们概述了在 DolphinScheduler 环境中启动 Arthas、监控特定 API 调用以及分析收集到的性能数据以增强调度可靠性和可维护性的步骤。
https://arthas.aliyun.com/download/latest_version?mirror=aliyun arthas-packaging-3.7.2-bin.zip cp arthas-packaging-3.7.2-bin.zip /opt/arthas cd /opt/arthas unzip arthas-packaging-3.7.2-bin.zip java -jar arthas-boot.jar Select the corresponding process ID.
[ERROR] Start arthas failed, exception stack trace: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106) at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:78) at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:250) at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:102) at com.taobao.arthas.core.Arthas.<init>(Arthas.java:27) at com.taobao.arthas.core.Arthas.main(Arthas.java:161)
解决方案:
在 ${DOLPHINSCHEUDLER_HOME}/api-server/bin 中,将以下行添加到 jvm_args_env.sh:
-XX:+StartAttachListener
Picked up JAVA_TOOL_OPTIONS: java.io.IOException: well-known file /tmp/.java_pid731688 is not secure: file should be owned by the current user (which is 0) but is owned by 989 at sun.tools.attach.LinuxVirtualMachine.checkPermissions(Native Method) at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:117) at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:78) at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:250) at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:102) at com.taobao.arthas.core.Arthas.<init>(Arthas.java:27) at com.taobao.arthas.core.Arthas.main(Arthas.java:161) [ERROR] Start arthas failed, exception stack trace: [ERROR] attach fail, targetPid: 731688
解决方案:
确保运行 Arthas 服务的用户与运行 DolphinScheduler 的用户匹配,以避免此错误。
Watch用于监控方法的具体执行细节,例如参数、返回值等
watch org.apache.dolphinscheduler.api.controller.UsersController queryUserList returnObj
[arthas@731688]$ watch org.apache.dolphinscheduler.api.controller.UsersController queryUserList returnObj Press Q or Ctrl+C to abort. Affect(class count: 1 , method count: 1) cost in 126 ms, listenerId: 2 method=org.apache.dolphinscheduler.api.controller.UsersController.queryUserList location=AtExit ts=2024-08-27 02:04:01; [cost=4.918943ms] result=@Result[ ...
Trace监控方法调用的深度,包括调用的方法以及每个方法的执行时间。
[arthas@973263]$ trace org.apache.dolphinscheduler.api.controller.UsersController queryUserList Press Q or Ctrl+C to abort. Affect(class count: 1 , method count: 1) cost in 319 ms, listenerId: 1 `---ts=2024-08-27 10:33:08;thread_name=qtp1836984213-26;id=26;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@439f5b3d `---[13.962731ms] org.apache.dolphinscheduler.api.controller.UsersController:queryUserList() +---[0.18% 0.025123ms ] org.apache.dolphinscheduler.api.controller.UsersController:checkPageParams() #130 +---[0.09% 0.012549ms ] org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils:handleEscapes() #131 `---[96.47% 13.469876ms ] org.apache.dolphinscheduler.api.service.UsersService:queryUserList() #132
要生成堆转储文件,请使用:
[arthas@973263]$ heapdump arthas-output/dump.hprof Dumping heap to arthas-output/dump.hprof ... Heap dump file created
使用 MAT 等工具分析转储文件以进行内存泄漏诊断。
使用内存检查JVM内存使用情况:
[arthas@973263]$ memory Memory used total max usage heap 485M 900M 900M 53.91% ps_eden_space 277M 327M 358M 77.61% ...
使用仪表板查看CPU使用情况,并通过thread -n thread_id识别特定线程以进行进一步检查。
以上是增强任务调度可靠性:在 DolphinScheduler 中集成 Arthas 进行 API 监控的详细内容。更多信息请关注PHP中文网其他相关文章!