使用dotnet-monitor sidecar模式 dump docker運行的dotnet程序.( 二 )


dotnet-monitor容器準備

  • 增加 Docker image 作為目標容器的sidecar 容器.
  • 暴露端口52323 #dotnet-monitor映射端口.
  • 增加容器啟動命令參數 --no-auth # 簡單粗暴的讓所有的API都不要鑒權.
  • 添加環境變量
    • DOTNETMONITOR_DiagnosticPort__ConnectionMode=Listen # 必須的.
    • DOTNETMONITOR_DiagnosticPort__EndpointName=/my_diagnostic_volume/diag.sock # 目標容器配置的DOTNET_DiagnosticPorts中的address.
    • DOTNETMONITOR_Storage__DumpTempFolder=/my_diagnostic_volume/dump_files # dump內存是用的目錄.
    • DOTNETMONITOR_Urls=http://+:52323 # dotnet-monitor要提供服務在什么端口上. dotnet-monitor默認用的就是52323.
詳細的文檔解釋看這里
至此, 所有的配置就都完成了.
使用dotnet-monitor 來dump目標容器的內存文件Get 請求 /dump endpoint 即可下載內存轉儲文件.
wget ip:52323/dump -O my_target_application_memory_dump.dmp| Route| Description| Version Introduced || ---------------- | ------------------------------------------------------------------ | ------------------ || /processes| Gets detailed information about discoverable processes.| 6.0|| /dump| Captures managed dumps of processes without using a debugger.| 6.0|| /gcdump| Captures GC dumps of processes.| 6.0|| /trace| Captures traces of processes without using a profiler.| 6.0|| /metrics| Captures metrics of a process in the Prometheus exposition format. | 6.0|| /livemetrics| Captures live metrics of a process.| 6.0|| /stacks| [Experimental] Gets the current callstacks of all .NET threads.| 7.0|| /logs| Captures logs of processes.| 6.0|| /info| Gets info about dotnet monitor.| 6.0|| /operations| Gets egress operation status or cancels operations.| 6.0|| /collectionrules | Gets the current state of collection rules.| 6.3|所有可用的API以及解釋, 請看這里API's
在之后的問內存文件的分析可以使用dotnet-dump程序.更多高級用法請查看, 例如可以配置內存每增加100Mb就觸發dump內存文件.
相關鏈接https://learn.microsoft.com/zh-cn/dotnet/core/diagnostics/dotnet-monitorhttps://learn.microsoft.com/zh-cn/dotnet/core/diagnostics/dotnet-dumphttps://learn.microsoft.com/zh-cn/dotnet/core/diagnostics/diagnostic-porthttps://github.com/dotnet/dotnet-monitor/blob/main/README.mdhttps://devblogs.microsoft.com/dotnet/announcing-dotnet-monitor-in-net-6/
【使用dotnet-monitor sidecar模式 dump docker運行的dotnet程序.】

推薦閱讀