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等依賴錯誤,安裝相關依賴重新三部曲即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM