centos7.4 openresty-1.15.8.2 火焰图安装测试

1、安装systemtap
其实主要就是安装内核探测工具 systemtap。(SystemTap 通过将脚本语句翻译成C语句,编译成内核模块。模块加载之后,依据时间处理机制来收集有关正在运行的Linux系统的信息)

#yum install yum-utils
#yum install kernel-devel
#debuginfo-install kernel
#yum install systemtap
第三步安装失败的话,则手动安装内核开发包和调试包:

查看内核版本号

 下载官方包

#wget "http://debuginfo.centos.org/7/x86_64/kernel-debuginfo-($version).rpm"

#wget "http://debuginfo.centos.org/7/x86_64/kernel-debuginfo-common-($version).rpm"

#rpm -ivh kernel-debuginfo-($version).rpm

#rpm -ivh kernel-debuginfo-common-($version).rpm

完成后输入以下命令进行测试

#stap -ve 'probe begin { log("hello world") exit() }'
如果安装成功则是这样

2、下载 openresty-systemtap-toolkit

#git clone https://github.com/openresty/nginx-systemtap-toolkit.git

要知道systemtap只是个内核探测工具,不只是可以用在openresty中的,你得自己写好脚本来进行埋点等工作。但是春哥已经在 openresty-systemtap-toolkit 中提供了许多可以直接使用的脚本,我们直接拿过来用就好了,毕竟我自己是不会写的。

3、下载 FlameGraph

#git clone https://github.com/brendangregg/FlameGraph.git
使用上面openresty-systemtap-toolkit这些脚本后,我们其实已经可以拿到我们所需要的信息了,只是还是不够直观,所以我们得用FlameGraph火焰图生成工具来生成直观的图片。

4、使用示例
a.找到我们要监控的nginx的某个进程
#ps -ef | grep nginx

b.ngx-sample-lua-bt 抓取栈信息(这个工具可以看到在某个文件对应行函数的情况)
此处我是把上面下载的openresty-systemtap-toolkit和FlameGraph加到环境变量里面去了。所以直接输入命令就行了

#ngx-sample-lua-bt -p 12322 --luajit20 -t 20 -u> temp.bt

参数 -p 表示要抓取的进程id,-t是探测的时间,单位是秒,-u表示抓取用户空间,对应的-k表示内核空间,探测结果输出到 temp.bt

c.使用fix-lua-bt把上面得到的文件转化更友好点(直接看到对应的lua函数)

fix-lua-bt temp.bt > a.bt
d.使用下面两个FlameGraph中的命令将文件转化为svg图片

stackcollapse-stap.pl a.bt > a.cbt
flamegraph.pl a.cbt > a.svg
然后打开a.svg就可以看到火焰图了。

5、踩坑点:

$ ./ngx-sample-lua-bt -p 12322 --luajit20 -t 5 > temp.bt

WARNING: cannot find module /usr/local/openresty/luajit/lib/libluajit-5.1.so.2.1.0 debuginfo: No DWARF information found [man warning::debuginfo]

WARNING: Bad $context variable being substituted with literal 0: identifier '$L' at <input>:17:30

source: lua_states[my_pid] = $L

semantic error: type definition 'TValue' not found in '/usr/local/openresty/luajit/lib/libluajit-5.1.so.2.1.0': operator '@cast' at :62:12

source: return @cast(tvalue, "TValue", "/usr/local/openresty/luajit/lib/libluajit-5.1.so.2.1.0")->fr->tp->ftsz

Pass 2: analysis failed. [man error::pass2]

Number of similar warning messages suppressed: 100.

Rerun with -v to see them.

原因是新版的openresty默认开启了gc-64,而工具是32位的

解决办法:重新编译安装openresty,加上编译选项 --without-luajit-gc64

#mv /usr/local/openresty /usr/local/openresty_bak

#cd /opt

#wget https://openresty.org/download/openresty-1.15.8.2.tar.gz

#tar zxvf openresty-1.15.8.2.tar.gz

#cd openresty-1.15.8.2

#./configure --prefix=/usr/local/openresty --without-luajit-gc64 --with-pcre-jit --with-stream --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-dtrace-probes --with-stream --with-http_ssl_module

#make

#make install

如果编译出现openssl,pcre等依赖错误,安装相关依赖重新三部曲即可。

猜你喜欢

转载自www.cnblogs.com/wuweidong/p/12468401.html