}
#endif
+ u->state->bytes_received = u->received;
+ u->state->bytes_sent = pc->sent;
+
ngx_close_connection(pc);
u->peer.connection = NULL;
}
u->resolved->ctx = NULL;
}
+ pc = u->peer.connection;
+
+ if (u->state) {
+ if (pc) {
+ u->state->bytes_received = u->received;
+ u->state->bytes_sent = pc->sent;
+ }
+ }
+
if (u->peer.free && u->peer.sockaddr) {
u->peer.free(&u->peer, u->peer.data, 0);
u->peer.sockaddr = NULL;
}
- pc = u->peer.connection;
-
if (pc) {
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
"close stream proxy upstream connection: %d", pc->fd);
static ngx_int_t ngx_stream_upstream_add_variables(ngx_conf_t *cf);
static ngx_int_t ngx_stream_upstream_addr_variable(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_stream_upstream_bytes_variable(ngx_stream_session_t *s,
+ ngx_stream_variable_value_t *v, uintptr_t data);
static char *ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd,
void *dummy);
ngx_stream_upstream_addr_variable, 0,
NGX_STREAM_VAR_NOCACHEABLE, 0 },
+ { ngx_string("upstream_bytes_sent"), NULL,
+ ngx_stream_upstream_bytes_variable, 0,
+ NGX_STREAM_VAR_NOCACHEABLE, 0 },
+
+ { ngx_string("upstream_bytes_received"), NULL,
+ ngx_stream_upstream_bytes_variable, 1,
+ NGX_STREAM_VAR_NOCACHEABLE, 0 },
+
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};
}
+static ngx_int_t
+ngx_stream_upstream_bytes_variable(ngx_stream_session_t *s,
+ ngx_stream_variable_value_t *v, uintptr_t data)
+{
+ u_char *p;
+ size_t len;
+ ngx_uint_t i;
+ ngx_stream_upstream_state_t *state;
+
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ if (s->upstream_states == NULL || s->upstream_states->nelts == 0) {
+ v->not_found = 1;
+ return NGX_OK;
+ }
+
+ len = s->upstream_states->nelts * (NGX_OFF_T_LEN + 2);
+
+ p = ngx_pnalloc(s->connection->pool, len);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ v->data = p;
+
+ i = 0;
+ state = s->upstream_states->elts;
+
+ for ( ;; ) {
+
+ if (data == 1) {
+ p = ngx_sprintf(p, "%O", state[i].bytes_received);
+
+ } else {
+ p = ngx_sprintf(p, "%O", state[i].bytes_sent);
+ }
+
+ if (++i == s->upstream_states->nelts) {
+ break;
+ }
+
+ *p++ = ',';
+ *p++ = ' ';
+ }
+
+ v->len = p - v->data;
+
+ return NGX_OK;
+}
+
+
static char *
ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{