7
7
8
8
typedef struct {
9
9
time_t ws_conn_start_time ;
10
+ ngx_frame_counter_t frame_counter ;
11
+
10
12
} ngx_http_websocket_stat_ctx ;
11
13
14
+ typedef struct {
15
+ ngx_int_t frames ;
16
+ ngx_int_t total_payload_size ;
17
+ ngx_int_t total_size ;
18
+ } ngx_http_websocket_stat_statistic_t ;
19
+
20
+ ngx_http_websocket_stat_statistic_t frames_in ;
21
+ ngx_http_websocket_stat_statistic_t frames_out ;
22
+
12
23
ngx_frame_counter_t frame_counter_in ;
13
24
ngx_frame_counter_t frame_counter_out ;
14
25
15
26
ngx_http_websocket_stat_ctx * stat_counter ;
16
27
typedef struct {
17
- ngx_frame_counter_t * counter ;
18
28
int from_client ;
19
29
ngx_http_websocket_stat_ctx * ws_ctx ;
20
30
@@ -137,9 +147,9 @@ ngx_http_websocket_stat_handler(ngx_http_request_t *r)
137
147
out .buf = b ;
138
148
out .next = NULL ;
139
149
sprintf ((char * )msg , (char * )responce_template , ngx_websocket_stat_active ,
140
- frame_counter_in .frames , frame_counter_in .total_payload_size ,
141
- frame_counter_in .total_size , frame_counter_out .frames ,
142
- frame_counter_out .total_payload_size , frame_counter_out .total_size );
150
+ frames_in .frames , frames_in .total_payload_size ,
151
+ frames_in .total_size , frames_out .frames ,
152
+ frames_out .total_payload_size , frames_out .total_size );
143
153
144
154
b -> pos = msg ; /* first position in memory of the data */
145
155
b -> last =
@@ -210,20 +220,20 @@ my_send(ngx_connection_t *c, u_char *buf, size_t size)
210
220
ngx_http_websocket_stat_ctx * ctx ;
211
221
ssize_t sz = size ;
212
222
u_char * buffer = buf ;
213
- ngx_frame_counter_t * frame_counter = & frame_counter_out ;
223
+ ngx_http_websocket_stat_statistic_t * frame_counter = & frames_out ;
214
224
frame_counter -> total_size += sz ;
215
225
ngx_http_request_t * r = c -> data ;
216
226
217
227
ctx = ngx_http_get_module_ctx (r , ngx_http_websocket_stat_module );
218
228
template_ctx_s template_ctx ;
219
- template_ctx .counter = frame_counter ;
220
229
template_ctx .from_client = 0 ;
221
230
template_ctx .ws_ctx = ctx ;
222
231
while (sz > 0 ) {
223
- if (frame_counter_process_message (& buffer , & sz , frame_counter )) {
232
+ if (frame_counter_process_message (& buffer , & sz ,
233
+ & (ctx -> frame_counter ))) {
224
234
frame_counter -> frames ++ ;
225
235
frame_counter -> total_payload_size +=
226
- frame_counter -> current_payload_size ;
236
+ ctx -> frame_counter . current_payload_size ;
227
237
char * log_line = apply_template (log_template , r , & template_ctx );
228
238
websocket_log (log_line );
229
239
free (log_line );
@@ -241,19 +251,18 @@ my_recv(ngx_connection_t *c, u_char *buf, size_t size)
241
251
242
252
ngx_http_websocket_stat_ctx * ctx ;
243
253
ssize_t sz = n ;
244
- ngx_frame_counter_t * frame_counter = & frame_counter_in ;
254
+ ngx_http_websocket_stat_statistic_t * frame_counter = & frames_in ;
245
255
ngx_http_request_t * r = c -> data ;
246
256
ctx = ngx_http_get_module_ctx (r , ngx_http_websocket_stat_module );
247
257
frame_counter -> total_size += n ;
248
258
template_ctx_s template_ctx ;
249
- template_ctx .counter = frame_counter ;
250
259
template_ctx .from_client = 1 ;
251
260
template_ctx .ws_ctx = ctx ;
252
261
while (sz > 0 ) {
253
- if (frame_counter_process_message (& buf , & sz , frame_counter )) {
262
+ if (frame_counter_process_message (& buf , & sz , & ctx -> frame_counter )) {
254
263
frame_counter -> frames ++ ;
255
264
frame_counter -> total_payload_size +=
256
- frame_counter -> current_payload_size ;
265
+ ctx -> frame_counter . current_payload_size ;
257
266
if (ws_log ) {
258
267
char * log_line = apply_template (log_template , r , & template_ctx );
259
268
websocket_log (log_line );
@@ -274,7 +283,6 @@ ngx_http_websocket_stat_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
274
283
ngx_http_websocket_stat_ctx * ctx ;
275
284
ctx = ngx_http_get_module_ctx (r , ngx_http_websocket_stat_module );
276
285
template_ctx_s template_ctx ;
277
- template_ctx .counter = NULL ;
278
286
template_ctx .ws_ctx = ctx ;
279
287
280
288
if (r -> upstream -> upgrade ) {
@@ -317,7 +325,7 @@ const char *
317
325
ws_packet_type (ngx_http_request_t * r , void * data )
318
326
{
319
327
template_ctx_s * ctx = data ;
320
- ngx_frame_counter_t * frame_cntr = ctx -> counter ;
328
+ ngx_frame_counter_t * frame_cntr = & ( ctx -> ws_ctx -> frame_counter ) ;
321
329
if (!ctx || !frame_cntr )
322
330
return UNKNOWN_VAR ;
323
331
sprintf (buff , "%d" , frame_cntr -> current_frame_type );
@@ -328,7 +336,7 @@ const char *
328
336
ws_packet_size (ngx_http_request_t * r , void * data )
329
337
{
330
338
template_ctx_s * ctx = data ;
331
- ngx_frame_counter_t * frame_cntr = ctx -> counter ;
339
+ ngx_frame_counter_t * frame_cntr = & ctx -> ws_ctx -> frame_counter ;
332
340
if (!ctx || !frame_cntr )
333
341
return UNKNOWN_VAR ;
334
342
sprintf (buff , "%lu" , frame_cntr -> current_payload_size );
0 commit comments