Nginx使用日誌輸出上游伺服器和自身的處理時間

牛平發表於2018-01-30
場景:
    Nginx的後端跟著Tomcat,現在要統計實現Nginx的處理時間以及後端伺服器的返回時間。

目的:
    對於一個客戶端請求,使用日誌輸出Nginx自身的處理時間,上游伺服器的處理時間。

實現:
    透過upstream模組的upstream_response_time變數來獲取相關資訊。
配置:

1.定義logformat
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
             '"$request" $status $body_bytes_sent '
             '"$http_referer" "$http_user_agent" '
             '$request_time $upstream_response_time $pipe';

request_time 表明,Nginx處理該請求所需花費的時間。
upstream_response_time 表明上游伺服器的處理時間。
pipe 表示是否使用了http pipe

使用該條日誌格式:

access_log /var/log/nginx/ timed_combined;

66.249.71.173 - - [08/Nov/2010:14:16:18 -0600] "GET /blog/2010/apr/30/installing-geodjango-dependencies-homebrew/ HTTP/1.1" 200 6569 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +)" 0.640 0.640 .

0.640 表示,Nginx使用了0.640s的時間去相應客戶端,其中上游伺服器佔用了0.640s,Nginx本身沒有花費任何時間,並且沒有使用pipeline

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29757574/viewspace-2150666/,如需轉載,請註明出處,否則將追究法律責任。

相關文章