diff options
author | Ruslan Ermilov <ru@nginx.com> | 2018-12-13 17:23:07 +0300 |
---|---|---|
committer | Ruslan Ermilov <ru@nginx.com> | 2018-12-13 17:23:07 +0300 |
commit | cb4dd56771c1af082bf3e810436712b4f48f2cf2 (patch) | |
tree | c70fedd149fbb5811a00d9ec1080e34a9578fa4d /src | |
parent | 8e2949e56a13405a157e05b21aa4c4a5fa468335 (diff) | |
download | nginx-cb4dd56771c1af082bf3e810436712b4f48f2cf2.tar.gz nginx-cb4dd56771c1af082bf3e810436712b4f48f2cf2.zip |
Upstream: implemented $upstream_bytes_sent.
Diffstat (limited to 'src')
-rw-r--r-- | src/http/ngx_http_upstream.c | 15 | ||||
-rw-r--r-- | src/http/ngx_http_upstream.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 3fa86c8f9..907105571 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -409,6 +409,10 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = { ngx_http_upstream_response_length_variable, 1, NGX_HTTP_VAR_NOCACHEABLE, 0 }, + { ngx_string("upstream_bytes_sent"), NULL, + ngx_http_upstream_response_length_variable, 2, + NGX_HTTP_VAR_NOCACHEABLE, 0 }, + #if (NGX_HTTP_CACHE) { ngx_string("upstream_cache_status"), NULL, @@ -4136,6 +4140,10 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, if (u->peer.sockaddr) { + if (u->peer.connection) { + u->state->bytes_sent = u->peer.connection->sent; + } + if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403 || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) { @@ -4319,6 +4327,10 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r, - u->pipe->preread_size; u->state->response_length = u->pipe->read_length; } + + if (u->peer.connection) { + u->state->bytes_sent = u->peer.connection->sent; + } } u->finalize_request(r, rc); @@ -5502,6 +5514,9 @@ ngx_http_upstream_response_length_variable(ngx_http_request_t *r, if (data == 1) { p = ngx_sprintf(p, "%O", state[i].bytes_received); + } else if (data == 2) { + p = ngx_sprintf(p, "%O", state[i].bytes_sent); + } else { p = ngx_sprintf(p, "%O", state[i].response_length); } diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h index af84e24be..6079d7236 100644 --- a/src/http/ngx_http_upstream.h +++ b/src/http/ngx_http_upstream.h @@ -64,6 +64,7 @@ typedef struct { ngx_msec_t queue_time; off_t response_length; off_t bytes_received; + off_t bytes_sent; ngx_str_t *peer; } ngx_http_upstream_state_t; |