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

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

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

查看内核版本号github

 下载官方包centos

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

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

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

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

完成后输入如下命令进行测试工具

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

 

 

二、下载 openresty-systemtap-toolkit

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

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

三、下载 FlameGraph

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

四、使用示例
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就能够看到火焰图了。

五、踩坑点:

$ ./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等依赖错误,安装相关依赖从新三部曲便可。

相关文章
相关标签/搜索