# HG changeset patch # User Vladimir Homutov # Date 1421215415 -10800 # Node ID 0a198a517eaf48baad03a76b182698c50496d380 # Parent e0920ea616326ec3e1ea8e3da5a8abc4fee918c7 Upstream: $upstream_header_time variable. Keeps time spent on obtaining the header from an upstream server. The value is formatted similar to the $upstream_response_time variable. diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -359,6 +359,10 @@ static ngx_http_variable_t ngx_http_ups ngx_http_upstream_status_variable, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, + { ngx_string("upstream_header_time"), NULL, + ngx_http_upstream_response_time_variable, 1, + NGX_HTTP_VAR_NOCACHEABLE, 0 }, + { ngx_string("upstream_response_time"), NULL, ngx_http_upstream_response_time_variable, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, @@ -1315,6 +1319,7 @@ ngx_http_upstream_connect(ngx_http_reque tp = ngx_timeofday(); u->state->response_sec = tp->sec; u->state->response_msec = tp->msec; + u->state->header_sec = (time_t) NGX_ERROR; rc = ngx_event_connect_peer(&u->peer); @@ -1836,6 +1841,7 @@ ngx_http_upstream_process_header(ngx_htt { ssize_t n; ngx_int_t rc; + ngx_time_t *tp; ngx_connection_t *c; c = u->peer.connection; @@ -1956,6 +1962,10 @@ ngx_http_upstream_process_header(ngx_htt /* rc == NGX_OK */ + tp = ngx_timeofday(); + u->state->header_sec = tp->sec - u->state->response_sec; + u->state->header_msec = tp->msec - u->state->response_msec; + if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) { if (ngx_http_upstream_test_next(r, u) == NGX_OK) { @@ -4822,8 +4832,18 @@ ngx_http_upstream_response_time_variable for ( ;; ) { if (state[i].status) { - ms = (ngx_msec_int_t) - (state[i].response_sec * 1000 + state[i].response_msec); + + if (data + && state[i].header_sec != (time_t) NGX_ERROR) + { + ms = (ngx_msec_int_t) + (state[i].header_sec * 1000 + state[i].header_msec); + + } else { + ms = (ngx_msec_int_t) + (state[i].response_sec * 1000 + state[i].response_msec); + } + ms = ngx_max(ms, 0); p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000); diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h --- a/src/http/ngx_http_upstream.h +++ b/src/http/ngx_http_upstream.h @@ -60,6 +60,8 @@ typedef struct { ngx_uint_t status; time_t response_sec; ngx_uint_t response_msec; + time_t header_sec; + ngx_uint_t header_msec; off_t response_length; ngx_str_t *peer;