如何对 kubernetes 的 pod 里运行的 openresty 进行 systemtap

142 views
Skip to first unread message

曾若瑜

unread,
May 31, 2017, 7:33:24 AM5/31/17
to openresty
我希望能对生产环境中运行的 openresty 进行一些 probe,例如查看 ngx.shared.DICT 的使用情况,但是生产环境运行在 docker 中,就遇到了如下麻烦:

环境:
  • docker 镜像:openresty/openresty:1.11.2.3-xenial,内核 4.4.0-66-generic
  • 主机:ubuntu 16.04,内核 4.4.0-66-generic,docker version:1.12.6
我尝试过以下几种方案:
  1. 在 Node 上安装 systemtap,对直接运行在主机上的 openresty worker 进程运行 systemtap,可以输出预期的结果并正常退出。
    sudo ./ngx-shm -<pid> -"-vv"
  2. 在 Node 上安装 systemtap,然后找到运行在 container 中的 openresty 进程对应的主机上的进程的 pid,报错:
    ERROR: Build-id mismatch [man error::buildid]: "/usr/local/openresty/nginx/sbin/nginx" byte 0 (0x2c vs 0x00) address 0x400284 rc -14
  3. 修改 ngx-shm 脚本
    my $nginx_path = <container_fs_root> . readlink $exec_file
    这次不报上面的错了,但是卡在
    Tracing 13831 (<container_fs_root>/usr/local/openresty/nginx/sbin/nginx)...
    把 verbose level 改成 -vvvv
    Tracing 13831 (<container_fs_root>/usr/local/openresty/nginx/sbin/nginx)...

    stapio:reader_thread:165 thread 0 start ppoll
    stapio:reader_thread:167 thread 0 end ppoll:0
    stapio:reader_thread:165 thread 0 start ppoll
    stapio:reader_thread:167 thread 0 end ppoll:0
    stapio:reader_thread:165 thread 0 start ppoll
    stapio:reader_thread:167 thread 0 end ppoll:0
    ...
    一直反复打上面两行 log,不会退出
  4. 以 privilege 方式运行 container,并把主机的 /lib/modules 和 /usr/src 都挂载到 pod 的相同位置,然后 docker exec 进入 container
    • 直接运行 systemtap
      stap -ve 'probe begin { log("hello world") exit() }'
      可以正常输出 hello world
    • 运行
      ./ngx-shm -<pid> -"-vv"
      也卡在和 3 一样的地方

我自己对于 systemtap 不熟,求各位分享一下对 docker 中的 openresty 进程进行 systemtap 的成功经验,谢谢!
Reply all
Reply to author
Forward
0 new messages