Welcome! Log In Create A New Profile

Advanced

[PATCH] Upstream: added $upstream_bytes_sent variable

Piotr Sikora via nginx-devel
November 27, 2018 05:36AM
# HG changeset patch
# User Piotr Sikora <piotrsikora@google.com>
# Date 1494129075 25200
# Sat May 06 20:51:15 2017 -0700
# Node ID fafbb3ee41e5bb03bcfba73f7d4367b8ab7d36cc
# Parent be5cb9c67c05ccaf22dab7abba78aa4c1545a8ee
Upstream: added $upstream_bytes_sent variable.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>

diff -r be5cb9c67c05 -r fafbb3ee41e5 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -162,8 +162,8 @@ static ngx_int_t ngx_http_upstream_statu
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_response_length_variable(
- ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_upstream_bytes_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_upstream_trailer_variable(ngx_http_request_t *r,
@@ -402,11 +402,15 @@ static ngx_http_variable_t ngx_http_ups
NGX_HTTP_VAR_NOCACHEABLE, 0 },

{ ngx_string("upstream_response_length"), NULL,
- ngx_http_upstream_response_length_variable, 0,
+ ngx_http_upstream_bytes_variable, 0,
NGX_HTTP_VAR_NOCACHEABLE, 0 },

{ ngx_string("upstream_bytes_received"), NULL,
- ngx_http_upstream_response_length_variable, 1,
+ ngx_http_upstream_bytes_variable, 1,
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
+ { ngx_string("upstream_bytes_sent"), NULL,
+ ngx_http_upstream_bytes_variable, 2,
NGX_HTTP_VAR_NOCACHEABLE, 0 },

#if (NGX_HTTP_CACHE)
@@ -4134,6 +4138,10 @@ ngx_http_upstream_next(ngx_http_request_
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http next upstream, %xi", ft_type);

+ if (u->state && u->state->bytes_sent == 0 && u->peer.connection) {
+ u->state->bytes_sent = u->peer.connection->sent;
+ }
+
if (u->peer.sockaddr) {

if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403
@@ -4319,6 +4327,10 @@ ngx_http_upstream_finalize_request(ngx_h
- u->pipe->preread_size;
u->state->response_length = u->pipe->read_length;
}
+
+ if (u->state->bytes_sent == 0 && u->peer.connection) {
+ u->state->bytes_sent = u->peer.connection->sent;
+ }
}

u->finalize_request(r, rc);
@@ -5468,7 +5480,7 @@ ngx_http_upstream_response_time_variable


static ngx_int_t
-ngx_http_upstream_response_length_variable(ngx_http_request_t *r,
+ngx_http_upstream_bytes_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
u_char *p;
@@ -5499,7 +5511,10 @@ ngx_http_upstream_response_length_variab

for ( ;; ) {

- if (data == 1) {
+ if (data == 2) {
+ p = ngx_sprintf(p, "%O", state[i].bytes_sent);
+
+ } else if (data == 1) {
p = ngx_sprintf(p, "%O", state[i].bytes_received);

} else {
diff -r be5cb9c67c05 -r fafbb3ee41e5 src/http/ngx_http_upstream.h
--- 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;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Upstream: added $upstream_bytes_sent variable

Piotr Sikora via nginx-devel 85 November 27, 2018 05:36AM

Re: [PATCH] Upstream: added $upstream_bytes_sent variable

Maxim Dounin 13 November 29, 2018 10:02AM

Re: [PATCH] Upstream: added $upstream_bytes_sent variable

Neil Craig 15 November 29, 2018 10:10AM

Re: [PATCH] Upstream: added $upstream_bytes_sent variable

ru@nginx.com 16 November 30, 2018 10:40AM

Re: [PATCH] Upstream: added $upstream_bytes_sent variable

Maxim Konovalov 11 December 05, 2018 11:16AM

Re: [PATCH] Upstream: added $upstream_bytes_sent variable

ru@nginx.com 9 December 13, 2018 09:28AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 71
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready