本文詳細介紹了將 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中文網其他相關文章!