Mercurial > hg > nginx-quic
comparison src/stream/ngx_stream_upstream.c @ 6676:df3a7c029dec
Stream: $upstream_bytes_sent and $upstream_bytes_received.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Fri, 02 Sep 2016 18:27:08 +0300 |
parents | ab9b4fd8c5b7 |
children | c02290241cbe |
comparison
equal
deleted
inserted
replaced
6675:ab9b4fd8c5b7 | 6676:df3a7c029dec |
---|---|
10 #include <ngx_stream.h> | 10 #include <ngx_stream.h> |
11 | 11 |
12 | 12 |
13 static ngx_int_t ngx_stream_upstream_add_variables(ngx_conf_t *cf); | 13 static ngx_int_t ngx_stream_upstream_add_variables(ngx_conf_t *cf); |
14 static ngx_int_t ngx_stream_upstream_addr_variable(ngx_stream_session_t *s, | 14 static ngx_int_t ngx_stream_upstream_addr_variable(ngx_stream_session_t *s, |
15 ngx_stream_variable_value_t *v, uintptr_t data); | |
16 static ngx_int_t ngx_stream_upstream_bytes_variable(ngx_stream_session_t *s, | |
15 ngx_stream_variable_value_t *v, uintptr_t data); | 17 ngx_stream_variable_value_t *v, uintptr_t data); |
16 | 18 |
17 static char *ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd, | 19 static char *ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd, |
18 void *dummy); | 20 void *dummy); |
19 static char *ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | 21 static char *ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, |
74 | 76 |
75 { ngx_string("upstream_addr"), NULL, | 77 { ngx_string("upstream_addr"), NULL, |
76 ngx_stream_upstream_addr_variable, 0, | 78 ngx_stream_upstream_addr_variable, 0, |
77 NGX_STREAM_VAR_NOCACHEABLE, 0 }, | 79 NGX_STREAM_VAR_NOCACHEABLE, 0 }, |
78 | 80 |
81 { ngx_string("upstream_bytes_sent"), NULL, | |
82 ngx_stream_upstream_bytes_variable, 0, | |
83 NGX_STREAM_VAR_NOCACHEABLE, 0 }, | |
84 | |
85 { ngx_string("upstream_bytes_received"), NULL, | |
86 ngx_stream_upstream_bytes_variable, 1, | |
87 NGX_STREAM_VAR_NOCACHEABLE, 0 }, | |
88 | |
79 { ngx_null_string, NULL, NULL, 0, 0, 0 } | 89 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
80 }; | 90 }; |
81 | 91 |
82 | 92 |
83 static ngx_int_t | 93 static ngx_int_t |
138 i = 0; | 148 i = 0; |
139 | 149 |
140 for ( ;; ) { | 150 for ( ;; ) { |
141 if (state[i].peer) { | 151 if (state[i].peer) { |
142 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); | 152 p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len); |
153 } | |
154 | |
155 if (++i == s->upstream_states->nelts) { | |
156 break; | |
157 } | |
158 | |
159 *p++ = ','; | |
160 *p++ = ' '; | |
161 } | |
162 | |
163 v->len = p - v->data; | |
164 | |
165 return NGX_OK; | |
166 } | |
167 | |
168 | |
169 static ngx_int_t | |
170 ngx_stream_upstream_bytes_variable(ngx_stream_session_t *s, | |
171 ngx_stream_variable_value_t *v, uintptr_t data) | |
172 { | |
173 u_char *p; | |
174 size_t len; | |
175 ngx_uint_t i; | |
176 ngx_stream_upstream_state_t *state; | |
177 | |
178 v->valid = 1; | |
179 v->no_cacheable = 0; | |
180 v->not_found = 0; | |
181 | |
182 if (s->upstream_states == NULL || s->upstream_states->nelts == 0) { | |
183 v->not_found = 1; | |
184 return NGX_OK; | |
185 } | |
186 | |
187 len = s->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
188 | |
189 p = ngx_pnalloc(s->connection->pool, len); | |
190 if (p == NULL) { | |
191 return NGX_ERROR; | |
192 } | |
193 | |
194 v->data = p; | |
195 | |
196 i = 0; | |
197 state = s->upstream_states->elts; | |
198 | |
199 for ( ;; ) { | |
200 | |
201 if (data == 1) { | |
202 p = ngx_sprintf(p, "%O", state[i].bytes_received); | |
203 | |
204 } else { | |
205 p = ngx_sprintf(p, "%O", state[i].bytes_sent); | |
143 } | 206 } |
144 | 207 |
145 if (++i == s->upstream_states->nelts) { | 208 if (++i == s->upstream_states->nelts) { |
146 break; | 209 break; |
147 } | 210 } |