mirror of
https://github.com/nginx/nginx.git
synced 2025-06-28 02:02:50 +08:00
Upstream: $upstream_connect_time.
The variable keeps time spent on establishing a connection with the upstream server.
This commit is contained in:
parent
b070e2d713
commit
4b9b16d27d
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user