使用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程序.】

推荐阅读