mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
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.
This commit is contained in:
parent
3149ddd320
commit
7e1eba5faa
@ -359,6 +359,10 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = {
|
||||
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_request_t *r, ngx_http_upstream_t *u)
|
||||
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_http_request_t *r, ngx_http_upstream_t *u)
|
||||
{
|
||||
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_http_request_t *r, ngx_http_upstream_t *u)
|
||||
|
||||
/* 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(ngx_http_request_t *r,
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user