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
index 5dd2bfb..0eb38ff 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -359,6 +359,10 @@
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 @@
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 @@
{
ssize_t n;
ngx_int_t rc;
+ ngx_time_t *tp;
ngx_connection_t *c;
c = u->peer.connection;
@@ -1956,6 +1962,10 @@
/* 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 @@
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
index 9d2ec93..98d7267 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -60,6 +60,8 @@
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;