此次恰好用到,親測可用。參照:http://www.javashuo.com/article/p-uhmdmcvk-ct.htmlhtml
項目中有些頁面時延不穩定,須要看每次接口調用時延,怎麼看,有兩種方法:一種是直接去catalina.out日誌中看,一種是直接去localhost_access_log日誌中看,第一種須要在代碼中實現時延的計算,第二種方法只需在server.xml中加一個簡單的配置。這裏只說第二種:web
一、打開tomcat下conf/server.xml,先看Host節點配置:apache
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
二、這時localhost_access_log最後一個是文件大小:tomcat
10.73.154.72 - - [12/Mar/2018:10:04:47 +0800] "POST /ms.sns.snsService/rewardHis HTTP/1.1" 200 133
三、在conf/server.xml的Host節點中Value節點最後的pattern參數中添加% Dapp
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b %D" />
四、從新打開localhost_access_log,加上了時延大小,單位是毫秒:webapp
10.125.40.179 - - [21/May/2018:14:12:22 +0800] "POST /ms.bkticket.myBookTicketService/getBookTicketRechargeList HTTP/1.1" 200 2519 62 10.125.40.179 - - [21/May/2018:14:12:22 +0800] "POST /ms.bkticket.myBookTicketService/getBookTicketRemainBalance HTTP/1.1" 200 589 72 10.125.40.179 - - [21/May/2018:14:12:23 +0800] "POST /ms.bkticket.myBookTicketService/getBookTicketRechargeList HTTP/1.1" 200 2096 47