aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@nginx.com>2015-05-16 01:32:27 +0300
committerRuslan Ermilov <ru@nginx.com>2015-05-16 01:32:27 +0300
commit4b9b16d27d51215edc38a55d929e522aad8234ff (patch)
treef9580fdd6d7e5dd039f47ecacff394976f508c1b
parentb070e2d71372eb16033727ba431fe6f4e4c434a3 (diff)
downloadnginx-4b9b16d27d51215edc38a55d929e522aad8234ff.tar.gz
nginx-4b9b16d27d51215edc38a55d929e522aad8234ff.zip
Upstream: $upstream_connect_time.
The variable keeps time spent on establishing a connection with the upstream server.
-rw-r--r--src/http/ngx_http_upstream.c14
-rw-r--r--src/http/ngx_http_upstream.h1
2 files changed, 14 insertions, 1 deletions
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 16a821558..47b574e84 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -363,6 +363,10 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = {
ngx_http_upstream_status_variable, 0,
NGX_HTTP_VAR_NOCACHEABLE, 0 },
+ { ngx_string("upstream_connect_time"), NULL,
+ ngx_http_upstream_response_time_variable, 2,
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
{ ngx_string("upstream_header_time"), NULL,
ngx_http_upstream_response_time_variable, 1,
NGX_HTTP_VAR_NOCACHEABLE, 0 },
@@ -1318,6 +1322,7 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
u->state->response_time = ngx_current_msec;
+ u->state->connect_time = (ngx_msec_t) -1;
u->state->header_time = (ngx_msec_t) -1;
rc = ngx_event_connect_peer(&u->peer);
@@ -1760,6 +1765,10 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http upstream send request");
+ if (u->state->connect_time == (ngx_msec_t) -1) {
+ u->state->connect_time = ngx_current_msec - u->state->response_time;
+ }
+
if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
return;
@@ -5009,9 +5018,12 @@ ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
for ( ;; ) {
if (state[i].status) {
- if (data && state[i].header_time != (ngx_msec_t) -1) {
+ if (data == 1 && state[i].header_time != (ngx_msec_t) -1) {
ms = state[i].header_time;
+ } else if (data == 2 && state[i].connect_time != (ngx_msec_t) -1) {
+ ms = state[i].connect_time;
+
} else {
ms = state[i].response_time;
}
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index edc1b6cad..64157e6a7 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -59,6 +59,7 @@ typedef struct {
ngx_uint_t status;
ngx_msec_t response_time;
+ ngx_msec_t connect_time;
ngx_msec_t header_time;
off_t response_length;