如题,有感于博客园最近多次翻车,感觉像胡子眉毛一把抓, 定位不了生产环境的问题。

抛开流程问题,思考在生产环境中如何做故障排除, 发现博客园里面这方面的文章比较少。



-----------------------------------在生产环境中故障排除--------------------------------

.Net 本身是提供了相关工具帮助我们在生产中故障排除: 
https://docs.microsoft.com/en-us/dotnet/framework/tools/sos-dll-sos-debugging-extension

<https://docs.microsoft.com/en-us/dotnet/framework/tools/sos-dll-sos-debugging-extension>

 工具的思路是在生产环境中dump出进程快照文件,通过分析快照堆栈、线程信息、异常信息判断运行状态。

这个工具依赖的文件很多很杂,国外大牛已经针对 .NetCore制作了工具镜像
<https://hub.docker.com/r/6opuc/lldb-netcore>



 

How to Use
docker run --rm -it -v /stripe/upload/coredump:/tmp/coredump 6opuc/lldb-netcore
* /stripe/upload/coredump - docker宿主机上崩溃进程的coredump文件路径
Usecases

  Analyze running container

  1.找到需要分析的容器id (docker ps),例如: b5063ef5787c

  2.运行包含 createdump工具的容器(需要sys_admin,sys_ptrace特权),
如果运行的容器已经包含这个特权,可附加到运行的容器并在容器中执行createdump工具
docker run --rm -it --cap-add sys_admin --cap-add sys_ptrace
--net=container:b5063ef5787c --pid=container:b5063ef5787c -v /tmp:/tmp
6opuc/lldb-netcore /bin/bash

*
 b5063ef5787c - 待分析的容器id

*
/tmp  - 主机上临时目录,coredump 文件将会在此生成

  3. 找到待分析dotnet 进程PID
ps aux
    这个例子PID 是“7”

  4. 生成dotnet进程的 coredump文件,并退出容器
createdump -u -f /tmp/coredump 7 # 7是dotnet 进程id
exit
  5. 使用debugger打开coredump文件
docker run --rm -it -v /tmp/coredump:/tmp/coredump 6opuc/lldb-netcore
    example output:
(lldb) target create "/usr/bin/dotnet" --core "/tmp/coredump" Core file '
/tmp/coredump' (x86_64) was loaded. (lldb) plugin load /coreclr/libsosplugin.so
(lldb) sos PrintException Thereis no current managed exception on this thread
(lldb)
  6. 在lldb shell 继续探索
help
   工具使用方式可参考
https://docs.microsoft.com/en-us/dotnet/framework/tools/sos-dll-sos-debugging-extension

<https://docs.microsoft.com/en-us/dotnet/framework/tools/sos-dll-sos-debugging-extension>

 

该DockerHub Repo还提供了基于docker 生产故障排除的常见用例
<https://hub.docker.com/r/6opuc/lldb-netcore-use-cases>:

* Process hang with idle CPU
<https://github.com/6opuc/lldb-netcore-use-cases/blob/master/hang_cpu_idle.md>
* Process hang with high CPU usage
<https://github.com/6opuc/lldb-netcore-use-cases/blob/master/hang_cpu_high.md>
* Process crash
<https://github.com/6opuc/lldb-netcore-use-cases/blob/master/crash.md>
* Excessive memory usage
<https://github.com/6opuc/lldb-netcore-use-cases/blob/master/memory.md>
 

这个镜像对于基于容器的故障排除相当有用,不敢自称原创镜像;

分享给大家, 希望园友通过经历生产环境的故障排除,进阶为资深研发。

 

+  dotnet core调试docker下生成的dump文件
<https://www.cnblogs.com/iamsach/p/10118628.html>

+ Windbg程序调试系列-索引篇 <https://www.cnblogs.com/tianqing/p/11307049.html>

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信