systemTap分析
本文主要通过案例演示的方式,介绍个人在使用systemtap对nginx(openresty)进行网络相关的探测的使用过程、使用感受以及过程中遇到的问题
背景介绍:
问题: 分析openresty(nginx)在出现abort时,为什么FIN正常关闭TCP连接,而不是使用RST?
第一步:需要知道如何添加探测点
- 探测点跟断点的概念类似,就是在指定位置,进行debug信息的输出
- 重要! 查看对应程序的所有function,以nginx为例
# 查看Nginx可用的探针点 sudo stap -L 'process("/usr/local/openresty/nginx/sbin/nginx").function("*")'(还有一种方式是:使用nm ./sbin/nginx,但是看不到参数和文件位置) # 看到的输出如下: ... process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_variables_add_core_vars@src/http/ngx_http_variables.c:2592") $cf:ngx_conf_t* process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_variables_init_vars@src/http/ngx_http_variables.c:2635") $cf:ngx_conf_t* $hash:ngx_hash_init_t process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_wait_request_handler@src/http/ngx_http_request.c:375") $rev:ngx_event_t* process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_weak_etag@src/http/ngx_http_core_module.c:1703") $r:ngx_http_request_t* process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_write_filter@src/http/ngx_http_write_filter_module.c:48") $r:ngx_http_request_t* $in:ngx_chain_t* process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_write_filter_init@src/http/ngx_http_write_filter_module.c:362") $cf:ngx_conf_t* process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_write_request_body@src/http/ngx_http_request_body.c:484") $r:ngx_http_request_t* process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_writer@src/http/ngx_http_request.c:2786") $r:ngx_http_request_t* process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_http_xss_body_filter@../xss-nginx-module-0.06/src/ngx_http_xss_filter_module.c:264") $r:ngx_http_request_t* $in:ngx_chain_t* $ll:ngx_chain_t**
- 找到需要添加探测点的函数、结构体、变量
- 假设我们需要找nginx中,某个URI的函数调用栈信息
- 添加探测点之前,我们需要一些基础知识。nginx关闭连接的标准函数为:
ngx_close_connection
- 通过如下命令,查看当前版本是否可以添加相应探测点这样我们确认当前的nginx版本存在函数,且得到该函数的第一个参数为
sudo stap -L 'process("/usr/local/openresty/nginx/sbin/nginx").function("*")'|grep ngx_close_connection process("/usr/local/openresty/nginx/sbin/nginx").function("ngx_close_connection@src/core/ngx_connection.c:1179") $c:ngx_connection_t*
$c
,属于结构体指针ngx_connection_t*
2025年4月11日...大约 4 分钟