接口耗时打印并统计

1.可以利用Tomcat的access-log日志,让其打印出http请求的每次耗时。可以在

config/server.xml里Host标签下配置tomcat访问日志格式

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; [%{postdata}r] %s %{Referer}i %{User-Agent}i %T %b" />

 

2.但这样只会打印每次的http请求耗时,并没有统计功能,如记录每个接口的平均耗时,记录超时接口,如超过1000ms的接口。

不直观的acces-log日志:10.118.129.28 4.1.5.24 - - 0.361 [28/Dec/2017:09:24:48 +0800] 361 GET /m/offerItem/queryOfferItemList?reqSystem=ICORE-PAP&idProfitOfferItem=&type=&subType=&name=&status=&pageNum=4&startTime=&endTime=&pageSize=10 HTTP/1.1 200 5468

10.118.129.28 4.1.5.24 - - 0.165 [28/Dec/2017:09:24:59 +0800] 165 GET /docc/giftConfig.jsp?tabId=f432ef47-e139-ec58-d81e-15aa7b348e2a&sysdate=1514424299261_0.5705513903091453 HTTP/1.1 200 16080
10.118.129.28 4.1.5.24 - - 0.005 [28/Dec/2017:09:24:59 +0800] 5 GET /js/giftConfig.js HTTP/1.1 304 -
10.118.129.28 4.1.5.24 - - 0.204 [28/Dec/2017:09:25:01 +0800] 204 GET /m/offer/getOfferList?reqSystem=ICORE-PAP&idProfitOffer=&name=&type=&subType=&status=&pageNum=1&pageSize=10 HTTP/1.1 200 3774


3.写个shell/python脚本分析这个日志,做好统计功能,频次每次+1,每次重新计算平均耗时
posted @ 2017-12-28 11:48  跨境电商杂货铺  阅读(1247)  评论(0编辑  收藏  举报