goreplay簡(jiǎn)介
gorreplay是一個(gè)開(kāi)源的網(wǎng)絡(luò)監(jiān)控工具。可以用來(lái)記錄流量,并用于回放、負(fù)載測(cè)試、監(jiān)控分析等。參考文檔:https://www.cnblogs.com/sunsky303/p/9072871.html
流量錄制
#捕獲9003端口的請(qǐng)求和響應(yīng)輸出到stdout(用于調(diào)試)
#--input-raw-track-response用于捕獲response,不加這個(gè)參數(shù)只捕獲請(qǐng)求
#--input-raw-override-snaplen將捕獲的snaplen覆蓋為64k,避免抓取的流量被截?cái)?./gor --input-raw :9003 --output-stdout --input-raw-track-response --input-raw-override-snaplen
# 捕獲9003端口的請(qǐng)求和響應(yīng)并轉(zhuǎn)發(fā)到x.x.x.x:9003服務(wù)上,output-http可以跟多個(gè),會(huì)將相同的流量轉(zhuǎn)發(fā)到多個(gè)端點(diǎn)
./gor --input-raw :9003 --output-http http://x.x.x.x:9003 --input-raw-track-response --input-raw-override-snaplen
# 捕獲9003端口的請(qǐng)求和響應(yīng)輸出到文件request.gor
./gor --input-raw :9003 --output-file request.gor --input-raw-track-response --input-raw-override-snaplen
# 捕獲9003端口的請(qǐng)求和響應(yīng)輸出到文件文件格式以當(dāng)前日期命名
./gor --input-raw :9003 --output-file requests-%Y-%m-%d.log --input-raw-override-snaplen
#捕獲9003端口的請(qǐng)求和響應(yīng)輸出到屏幕,并在請(qǐng)求header中添加‘Real-IP:真實(shí)ip’的字段,如果有則覆蓋原有值
./gor --input-raw :9003 --output-stdout --input-raw-track-response --input-raw-override-snaplen --input-raw-realip-header "Real-IP"
# --output-file-append gor默認(rèn)以塊的形式寫(xiě)入文件,默認(rèn)256塊(可以理解為256次請(qǐng)求),使用此參數(shù)可以將所有的塊寫(xiě)入一個(gè)文件,文件大小限制默認(rèn)32mb
./gor --input-raw :9003 --output-file request.gor --input-raw-track-response --input-raw-override-snaplen --output-file-append
#--output-file-size-limit和--output-file-queue-limit選項(xiàng)設(shè)置塊限制,默認(rèn)值分別為32mb、256,文件大小可以使用kb、mb、gb限制,只想要大小限制,你可以設(shè)置--output-file-queue-limit為0,反之亦然
#設(shè)置錄制的文件大小為40kb,不限制塊大小
./gor --input-raw :9003 --output-file request.gor --input-raw-override-snaplen --output-file-size-limit 40kb --output-file-queue-limit 0
流量回放
# 從request_0.gor文件中回放請(qǐng)求到x.x.x.x:9003服務(wù)上
./gor --input-file request_0.gor --output-http http://x.x.x.x:9003
# --input-file-loop從request_0.gor文件中回放請(qǐng)求到x.x.x.x:9003服務(wù)上,循環(huán)回放
./gor --input-file request_0.gor --output-http http://x.x.x.x:9003 --input-file-loop
# 以2倍的速度從requests-2022-01-18_0.log文件中回放請(qǐng)求到x.x.x.x:9003服務(wù)上
./gor --input-file 'requests-2022-01-18_0.log|200%' --output-http http://x.x.x.x:9003
#模擬從文件requests-2022-01-18_0.log回放查看需要回放需要執(zhí)行多長(zhǎng)時(shí)間
#--input-file-dry-run模擬從數(shù)據(jù)源讀取并不真正的回放,可以獲得回放的時(shí)間、回放的請(qǐng)求數(shù)等等
./gor --input-file ./gortest/requests-2022-01-18_0.log --output-http http://x.x.x.x:9003 --input-file-dry-run
#這里使用了通配符*,gor會(huì)自動(dòng)讀取匹配的所有文件并按照時(shí)間自動(dòng)排序
./gor --input-file './gortest/requests-2022-01-18_*' --output-http http://x.x.x.x:9003 --input-file-dry-run
中間件
./gor --input-raw :9003 --middleware "python3 middleware.py" -output-http http://x.x.x.x:9003 --input-raw-track-response --input-raw-override-snaplen