comparison src/http/ngx_http_upstream.c @ 7429:e573d74299a0

Upstream: implemented $upstream_bytes_sent.
author Ruslan Ermilov <ru@nginx.com>
date Thu, 13 Dec 2018 17:23:07 +0300
parents 860d3907da1c
children 608810849b6d
comparison
equal deleted inserted replaced
7428:cbc5dee8d5d2 7429:e573d74299a0
407 407
408 { ngx_string("upstream_bytes_received"), NULL, 408 { ngx_string("upstream_bytes_received"), NULL,
409 ngx_http_upstream_response_length_variable, 1, 409 ngx_http_upstream_response_length_variable, 1,
410 NGX_HTTP_VAR_NOCACHEABLE, 0 }, 410 NGX_HTTP_VAR_NOCACHEABLE, 0 },
411 411
412 { ngx_string("upstream_bytes_sent"), NULL,
413 ngx_http_upstream_response_length_variable, 2,
414 NGX_HTTP_VAR_NOCACHEABLE, 0 },
415
412 #if (NGX_HTTP_CACHE) 416 #if (NGX_HTTP_CACHE)
413 417
414 { ngx_string("upstream_cache_status"), NULL, 418 { ngx_string("upstream_cache_status"), NULL,
415 ngx_http_upstream_cache_status, 0, 419 ngx_http_upstream_cache_status, 0,
416 NGX_HTTP_VAR_NOCACHEABLE, 0 }, 420 NGX_HTTP_VAR_NOCACHEABLE, 0 },
4134 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 4138 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
4135 "http next upstream, %xi", ft_type); 4139 "http next upstream, %xi", ft_type);
4136 4140
4137 if (u->peer.sockaddr) { 4141 if (u->peer.sockaddr) {
4138 4142
4143 if (u->peer.connection) {
4144 u->state->bytes_sent = u->peer.connection->sent;
4145 }
4146
4139 if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403 4147 if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403
4140 || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) 4148 || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404)
4141 { 4149 {
4142 state = NGX_PEER_NEXT; 4150 state = NGX_PEER_NEXT;
4143 4151
4316 4324
4317 if (u->pipe && u->pipe->read_length) { 4325 if (u->pipe && u->pipe->read_length) {
4318 u->state->bytes_received += u->pipe->read_length 4326 u->state->bytes_received += u->pipe->read_length
4319 - u->pipe->preread_size; 4327 - u->pipe->preread_size;
4320 u->state->response_length = u->pipe->read_length; 4328 u->state->response_length = u->pipe->read_length;
4329 }
4330
4331 if (u->peer.connection) {
4332 u->state->bytes_sent = u->peer.connection->sent;
4321 } 4333 }
4322 } 4334 }
4323 4335
4324 u->finalize_request(r, rc); 4336 u->finalize_request(r, rc);
4325 4337
5499 5511
5500 for ( ;; ) { 5512 for ( ;; ) {
5501 5513
5502 if (data == 1) { 5514 if (data == 1) {
5503 p = ngx_sprintf(p, "%O", state[i].bytes_received); 5515 p = ngx_sprintf(p, "%O", state[i].bytes_received);
5516
5517 } else if (data == 2) {
5518 p = ngx_sprintf(p, "%O", state[i].bytes_sent);
5504 5519
5505 } else { 5520 } else {
5506 p = ngx_sprintf(p, "%O", state[i].response_length); 5521 p = ngx_sprintf(p, "%O", state[i].response_length);
5507 } 5522 }
5508 5523