浏览 901
1)安装
下载ngx_trace模块并且编译nginx
% ./configure --add-module=/path/to/ngx_trace && make
确保nginx二进制代码可以工作
% ./objs/nginx -V
准备nginx的运行环境
% mkdir mynginx
% mkdir mynginx/logs
% cp -r conf mynginx/
% cp -r html mynginx/
编辑nginx配置文件nginx.conf. 确保nginx以前台模式运行在单进程结构下。还要确保使用的socket端口当前用户可以使用。
daemon off;
master_process off;
...
http {
server {
listen 5678;
...
把错误重定向到stderr也很有用
error_log /dev/stderr debug;
使用 tracerx.pl脚本查看调用栈:
% /path/to/ngx_trace/tracerx.pl ./objs/nginx -p mynginx
精细定位: 打印 文件名, 行号, http event模块的调用,并且忽略access.log的信息:
% ./tracerx.pl -l -f 'core/ngx_conn|http/|event/' \
-i 'get_indexed_variable|_log_' \
./objs/nginx -p mynginx
语法:
tracerx.pl [OPTIONS] COMMAND [ARGS]
选项:
-l print filename, line number saved from "nm -l" and time offset
-s PATTERN
print calls matching specified regex pattern only
-i PATTERN
ignore calls matching regex pattern
-f PATTERN
print calls if filename matches pattern
-t show how much time it took to run each function in microseconds
-u show addresses of unknown functions
举例:
Show all calls within src/http and src/event modules:
% ./tracerx.pl -f 'src/http|src/event' ./objs/nginx -p mynginx
Show calls within http and ignore all calls containing _log_ in function
name:
% ./tracerx.pl -f 'src/http' -i '_log_' ./objs/nginx -p mynginx
模块代码:
https://github.com/PiotrSikora/ngx_trace
模块作者:
Alexandr Gomoliako <zzz@zzz.org.ua>
或者
alexandr.gomoliako@gmail.com
模块版权类型:
双版权: 1) GPL 或者 Artistic License
2) Apache 2.0 License
按点赞数排序
按时间排序