address[,(listen|connect)][,(suspend|nosuspend)]
详情请查看文档configure additional diagnostic ports
如果我们的需要dump内存文件, 可能会遇到WriteDumpAsync failed - HRESULT: 0x00000000
issues 1783这样的错误, 是因为权限问题.比如我在AWS Fargate
中遇到的就是 /dump
API 返回400错误 Write dump failed - HRESULT: 0x00000000
, 目标程序输出日志 ptrace(ATTACH, 1) FAILED Operation not permitted
.解决这个需要吧SYS_PTRACE权限给到目标程序. AWS Fargate
是编辑任务定义的json文件增加这一部分, docker 启动是通过增加--cap-add=SYS_PTRACE
参数.
{"linuxParameters": {"capabilities": {"add": ["SYS_PTRACE"]}}}
最后, 配置目标程序容器依赖dotnet-monitor容器, 这样可以先让dotnet-monitor容器启动后, 在启动目标程序容器.到此, 目标程序容器的配置就完成了, 接下来配置dotnet-monitor
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程序.】
经验总结扩展阅读
- 一次 Redis 事务使用不当引发的生产事故
- 抖音访客记录时间会错乱吗
- 秋天晚上睡觉可以开加湿器吗 秋季加湿器使用注意事项
- 加湿器的雾气能直接吸入肺部吗 加湿器使用注意事项
- 还在使用@Autowrired注入?不妨试试@RequiredArgsConstructor
- Java并发编程 | Synchronized原理与使用
- 苹果手机如何使用WiFi万能钥匙(苹果手机怎么添加钥匙)
- python3使用mutagen进行音频元数据处理
- Sentinel 介绍与下载使用
- 怎样使用万能wifi钥匙(最牛逼的wifi连接)