forked from zealot83/ngx_http_extended_status_module
-
Notifications
You must be signed in to change notification settings - Fork 3
/
extended_status-1.4.2.patch
770 lines (683 loc) · 21.3 KB
/
extended_status-1.4.2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
diff -ur nginx-1.4.2/src/core/ngx_connection.c nginx-1.4.2_extended_status/src/core/ngx_connection.c
--- nginx-1.4.2/src/core/ngx_connection.c 2013-07-17 14:51:21.000000000 +0200
+++ nginx-1.4.2_extended_status/src/core/ngx_connection.c 2013-07-25 16:24:20.000000000 +0200
@@ -760,6 +760,9 @@
ngx_uint_t instance;
ngx_event_t *rev, *wev;
ngx_connection_t *c;
+#if (NGX_STAT_EXTENDED)
+ conn_score *cs;
+#endif
/* disable warning: Win32 SOCKET is u_int while UNIX socket is int */
@@ -802,8 +805,16 @@
rev = c->read;
wev = c->write;
+#if (NGX_STAT_EXTENDED)
+ cs = c->cs;
+#endif
+
ngx_memzero(c, sizeof(ngx_connection_t));
+#if (NGX_STAT_EXTENDED)
+ c->cs = cs;
+#endif
+
c->read = rev;
c->write = wev;
c->fd = s;
diff -ur nginx-1.4.2/src/core/ngx_connection.h nginx-1.4.2_extended_status/src/core/ngx_connection.h
--- nginx-1.4.2/src/core/ngx_connection.h 2013-07-17 14:51:21.000000000 +0200
+++ nginx-1.4.2_extended_status/src/core/ngx_connection.h 2013-07-25 16:24:20.000000000 +0200
@@ -111,6 +111,11 @@
struct ngx_connection_s {
+
+#if (NGX_STAT_EXTENDED)
+ void *cs;
+#endif
+
void *data;
ngx_event_t *read;
ngx_event_t *write;
diff -ur nginx-1.4.2/src/event/ngx_event_accept.c nginx-1.4.2_extended_status/src/event/ngx_event_accept.c
--- nginx-1.4.2/src/event/ngx_event_accept.c 2013-07-17 14:51:21.000000000 +0200
+++ nginx-1.4.2_extended_status/src/event/ngx_event_accept.c 2013-07-25 16:24:20.000000000 +0200
@@ -134,7 +134,7 @@
return;
}
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
(void) ngx_atomic_fetch_add(ngx_stat_accepted, 1);
#endif
@@ -152,10 +152,15 @@
return;
}
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
(void) ngx_atomic_fetch_add(ngx_stat_active, 1);
#endif
+#if (NGX_STAT_EXTENDED)
+ set_conn_active(c);
+ set_conn_mode(c, SERVER_READY);
+#endif
+
c->pool = ngx_create_pool(ls->pool_size, ev->log);
if (c->pool == NULL) {
ngx_close_accepted_connection(c);
@@ -257,7 +262,7 @@
c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1);
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
(void) ngx_atomic_fetch_add(ngx_stat_handled, 1);
#endif
@@ -491,9 +496,14 @@
ngx_destroy_pool(c->pool);
}
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
(void) ngx_atomic_fetch_add(ngx_stat_active, -1);
#endif
+
+#if (NGX_STAT_EXTENDED)
+ set_conn_inactive(c);
+ set_conn_mode(c, SERVER_DEAD);
+#endif
}
diff -ur nginx-1.4.2/src/event/ngx_event.c nginx-1.4.2_extended_status/src/event/ngx_event.c
--- nginx-1.4.2/src/event/ngx_event.c 2013-07-17 14:51:21.000000000 +0200
+++ nginx-1.4.2_extended_status/src/event/ngx_event.c 2013-07-25 16:24:20.000000000 +0200
@@ -59,7 +59,7 @@
ngx_file_t ngx_accept_mutex_lock_file;
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
ngx_atomic_t ngx_stat_accepted0;
ngx_atomic_t *ngx_stat_accepted = &ngx_stat_accepted0;
@@ -78,7 +78,15 @@
#endif
+#if (NGX_STAT_EXTENDED)
+ngx_uint_t ngx_num_workers;
+size_t shm_size = 0;
+worker_score *workers;
+conn_score *conns;
+worker_score *my_worker;
+
+#endif
static ngx_command_t ngx_events_commands[] = {
@@ -346,6 +354,40 @@
return NGX_OK;
}
+#if (NGX_STAT_EXTENDED)
+
+static void
+init_request_cnt(request_cnt *recent_request_cnt)
+{
+ ngx_uint_t i;
+
+ for (i = 0; i < RECENT_PERIOD; i++) {
+ recent_request_cnt[i].time = 0;
+ recent_request_cnt[i].cnt = 0;
+ }
+}
+
+
+static void
+init_workers(worker_score *workers)
+{
+ worker_score *ws;
+ ngx_uint_t i;
+
+ for (i = 0; i < ngx_num_workers; i++)
+ {
+ ws = (worker_score *)((char *) workers + WORKER_SCORE_LEN * i);
+
+ ws->pid = 0;
+ ws->access_count = 0;
+ ws->bytes_sent = 0;
+ ws->mode = SERVER_READY;
+
+ init_request_cnt(ws->recent_request_cnt);
+ }
+}
+
+#endif
ngx_int_t
ngx_handle_write_event(ngx_event_t *wev, size_t lowat)
@@ -494,7 +536,13 @@
}
if (ngx_accept_mutex_ptr) {
+#if (NGX_STAT_EXTENDED)
+ shm.addr = (u_char *) ngx_accept_mutex_ptr;
+ shm.size = shm_size;
+ ngx_shm_free(&shm);
+#else
return NGX_OK;
+#endif
}
@@ -506,7 +554,7 @@
+ cl /* ngx_connection_counter */
+ cl; /* ngx_temp_number */
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
size += cl /* ngx_stat_accepted */
+ cl /* ngx_stat_handled */
@@ -518,6 +566,20 @@
#endif
+#if (NGX_STAT_EXTENDED)
+
+ if (WORKER_SCORE_LEN < sizeof(worker_score)) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "worker_score(%d) too large", sizeof(worker_score ));
+ return NGX_ERROR;
+ }
+
+ size += (WORKER_SCORE_LEN * ccf->worker_processes)
+ + (sizeof(conn_score) * ccf->worker_processes * cycle->connection_n);
+
+ shm_size = size;
+
+#endif
+
shm.size = size;
shm.name.len = sizeof("nginx_shared_zone");
shm.name.data = (u_char *) "nginx_shared_zone";
@@ -553,7 +615,7 @@
ngx_random_number = (tp->msec << 16) + ngx_pid;
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
ngx_stat_accepted = (ngx_atomic_t *) (shared + 3 * cl);
ngx_stat_handled = (ngx_atomic_t *) (shared + 4 * cl);
@@ -565,6 +627,17 @@
#endif
+#if (NGX_STAT_EXTENDED)
+
+ ngx_num_workers = ccf->worker_processes;
+
+ workers = (worker_score *) (shared + 10 * cl);
+ init_workers(workers);
+
+ conns = (conn_score *) (shared + 10 * cl + ccf->worker_processes * WORKER_SCORE_LEN);
+
+#endif
+
return NGX_OK;
}
@@ -703,6 +776,37 @@
c = cycle->connections;
+#if (NGX_STAT_EXTENDED)
+ {
+ ngx_time_t *tp;
+ conn_score *cs;
+ ngx_uint_t i;
+
+ for (i = 0; i < cycle->connection_n; i++)
+ {
+ c [i].cs = (void *) ((char *) conns +
+ sizeof(conn_score) * (ngx_process_slot * cycle->connection_n + i));
+ cs = (conn_score *) c[i].cs;
+
+ cs->bytes_sent = 0;
+ cs->access_count = 0;
+ cs->response_time = 0;
+ cs->upstream_response_time = -1;
+ cs->request[0] = '\0';
+ cs->client[0] = '\0';
+ cs->vhost[0] = '\0';
+ cs->mode = SERVER_READY;
+
+ tp = ngx_timeofday();
+ cs->last_used = tp->sec;
+ cs->status = 0;
+ cs->zin = 0;
+ cs->zout = 0;
+ cs->active = 0;
+ }
+ }
+#endif
+
cycle->read_events = ngx_alloc(sizeof(ngx_event_t) * cycle->connection_n,
cycle->log);
if (cycle->read_events == NULL) {
diff -ur nginx-1.4.2/src/event/ngx_event.h nginx-1.4.2_extended_status/src/event/ngx_event.h
--- nginx-1.4.2/src/event/ngx_event.h 2013-07-17 14:51:21.000000000 +0200
+++ nginx-1.4.2_extended_status/src/event/ngx_event.h 2013-07-25 16:24:20.000000000 +0200
@@ -8,7 +8,9 @@
#ifndef _NGX_EVENT_H_INCLUDED_
#define _NGX_EVENT_H_INCLUDED_
-
+#if (NGX_STAT_EXTENDED)
+#include <sys/times.h>
+#endif
#include <ngx_config.h>
#include <ngx_core.h>
@@ -503,7 +505,7 @@
extern ngx_int_t ngx_accept_disabled;
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
extern ngx_atomic_t *ngx_stat_accepted;
extern ngx_atomic_t *ngx_stat_handled;
@@ -515,6 +517,87 @@
#endif
+#if (NGX_STAT_EXTENDED)
+
+#define SCORE__REQUEST_LEN 128
+#define SCORE__CLIENT_LEN 32
+#define SCORE__VHOST_LEN 32
+
+#define CL_SIZE 128
+#define WORKER_SCORE_LEN 640 /* 128 X 5 */
+
+#define SERVER_READY '-'
+#define SERVER_BUSY_READ 'R'
+#define SERVER_BUSY_WRITE 'W'
+#define SERVER_BUSY_LOG 'L'
+#define SERVER_DEAD 'I'
+
+#define RECENT_PERIOD 64
+#define RECENT_MASK 0x0000003F
+
+typedef struct {
+ uint32_t time;
+ uint32_t cnt;
+} request_cnt;
+
+
+typedef struct {
+ request_cnt recent_request_cnt[RECENT_PERIOD];
+ struct tms times;
+ time_t last_used;
+ ngx_uint_t bytes_sent;
+ ngx_uint_t access_count;
+ ngx_pid_t pid;
+ char mode;
+} worker_score;
+
+
+typedef struct {
+ u_char request[SCORE__REQUEST_LEN];
+ u_char client[SCORE__CLIENT_LEN];
+ u_char vhost[SCORE__VHOST_LEN];
+ time_t last_used;
+ ngx_uint_t bytes_sent;
+ ngx_uint_t access_count;
+ char mode ;
+ ngx_msec_int_t response_time;
+ ngx_msec_int_t upstream_response_time;
+ ngx_uint_t status;
+ size_t zin;
+ size_t zout;
+ char active;
+} conn_score;
+
+
+extern worker_score *workers;
+extern worker_score *my_worker;
+extern conn_score *conns;
+
+
+static inline void
+set_conn_active(ngx_connection_t *c)
+{
+ conn_score *score = (conn_score *) c->cs;
+ score->active = 1 ;
+}
+
+
+static inline void
+set_conn_inactive(ngx_connection_t *c)
+{
+ conn_score *score = (conn_score *) c->cs;
+ score->active = 0 ;
+}
+
+
+static inline void
+set_conn_mode(ngx_connection_t *c, char mode)
+{
+ conn_score *score = (conn_score *) c->cs;
+ score->mode = mode ;
+}
+
+#endif
#define NGX_UPDATE_TIME 1
#define NGX_POST_EVENTS 2
diff -ur nginx-1.4.2/src/http/modules/ngx_http_gzip_filter_module.c nginx-1.4.2_extended_status/src/http/modules/ngx_http_gzip_filter_module.c
--- nginx-1.4.2/src/http/modules/ngx_http_gzip_filter_module.c 2013-07-17 14:51:22.000000000 +0200
+++ nginx-1.4.2_extended_status/src/http/modules/ngx_http_gzip_filter_module.c 2013-07-25 16:24:20.000000000 +0200
@@ -971,6 +971,15 @@
r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED;
+#if (NGX_STAT_EXTENDED)
+ {
+ conn_score *cs = r->connection->cs;
+
+ cs->zin = ctx->zin;
+ cs->zout = ctx->zout;
+ }
+#endif
+
return NGX_OK;
}
diff -ur nginx-1.4.2/src/http/ngx_http_request.c nginx-1.4.2_extended_status/src/http/ngx_http_request.c
--- nginx-1.4.2/src/http/ngx_http_request.c 2013-07-17 14:51:22.000000000 +0200
+++ nginx-1.4.2_extended_status/src/http/ngx_http_request.c 2013-07-25 16:50:00.000000000 +0200
@@ -587,12 +587,23 @@
ctx->current_request = r;
r->log_handler = ngx_http_log_error_handler;
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
(void) ngx_atomic_fetch_add(ngx_stat_reading, 1);
r->stat_reading = 1;
(void) ngx_atomic_fetch_add(ngx_stat_requests, 1);
#endif
+#if (NGX_STAT_EXTENDED)
+ {
+ conn_score *cs = (conn_score *) c->cs;
+ ngx_time_t *tp = ngx_timeofday();
+
+ my_worker->mode = SERVER_BUSY_READ;
+ set_conn_mode(c, SERVER_BUSY_READ);
+ cs->last_used = tp->sec;
+ }
+#endif
+
return r;
}
@@ -1837,13 +1848,18 @@
ngx_del_timer(c->read);
}
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
(void) ngx_atomic_fetch_add(ngx_stat_reading, -1);
r->stat_reading = 0;
(void) ngx_atomic_fetch_add(ngx_stat_writing, 1);
r->stat_writing = 1;
#endif
+#if (NGX_STAT_EXTENDED)
+ my_worker->mode = SERVER_BUSY_WRITE;
+ set_conn_mode(c, SERVER_BUSY_WRITE);
+#endif
+
c->read->handler = ngx_http_request_handler;
c->write->handler = ngx_http_request_handler;
r->read_event_handler = ngx_http_block_reading;
@@ -3289,6 +3305,60 @@
return NGX_OK;
}
+#if (NGX_STAT_EXTENDED)
+
+static inline void
+update_request_cnt(worker_score *worker, conn_score *cs, uint32_t sec)
+{
+ uint32_t index;
+
+ index = sec & RECENT_MASK;
+ if (sec == worker->recent_request_cnt[index].time) {
+ worker->recent_request_cnt[index].cnt += 1;
+ }
+ else {
+ worker->recent_request_cnt[index].time = sec;
+ worker->recent_request_cnt[index].cnt = 1;
+ }
+}
+
+
+static inline ngx_msec_int_t
+get_response_time(ngx_time_t *tp, ngx_http_request_t *r)
+{
+ ngx_msec_int_t ms;
+
+ ms = (ngx_msec_int_t) ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec));
+ ms = ( 0 <= ms ) ? ms : 0;
+
+ return ms;
+}
+
+static inline ngx_msec_int_t
+get_proxy_response_time(ngx_http_request_t *r)
+{
+ ngx_http_upstream_state_t *state;
+ ngx_msec_int_t ms = -1;
+ ngx_uint_t i;
+
+ if (NULL != r->upstream_states && 0 < r->upstream_states->nelts)
+ {
+ state = r->upstream_states->elts;
+ for (i = 0; i < r->upstream_states->nelts; i++)
+ {
+ if (0 != state[i].status)
+ {
+ ms = (ngx_msec_int_t) (state[i].response_sec * 1000 + state [i].response_msec);
+ ms = (0 <= ms) ? ms : 0;
+ break;
+ }
+ }
+ }
+
+ return ms;
+}
+
+#endif
static void
ngx_http_close_request(ngx_http_request_t *r, ngx_int_t rc)
@@ -3333,6 +3403,11 @@
ngx_http_log_ctx_t *ctx;
ngx_http_core_loc_conf_t *clcf;
+#if (NGX_STAT_EXTENDED)
+ conn_score *cs = r->connection->cs;
+ ngx_time_t *tp ;
+#endif
+
log = r->connection->log;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http close request");
@@ -3348,7 +3423,7 @@
}
}
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
if (r->stat_reading) {
(void) ngx_atomic_fetch_add(ngx_stat_reading, -1);
@@ -3366,6 +3441,49 @@
log->action = "logging request";
+#if (NGX_STAT_EXTENDED)
+ my_worker->mode = SERVER_BUSY_LOG;
+ set_conn_mode(r->connection, SERVER_BUSY_LOG);
+
+ if (0 < r->headers_in.server.len && NULL != r->request_line.data) {
+
+ tp = ngx_timeofday();
+
+ if (my_worker->last_used != tp->sec)
+ times(&(my_worker->times ));
+
+ my_worker->last_used = tp->sec;
+ cs->last_used = tp->sec;
+
+ cs->response_time = get_response_time(tp, r);
+ cs->upstream_response_time = get_proxy_response_time(r);
+
+ my_worker->bytes_sent += r->connection->sent;
+ cs->bytes_sent = r->connection->sent;
+
+ my_worker->access_count++;
+ cs->access_count++;
+
+ update_request_cnt(my_worker, cs, (uint32_t) tp->sec);
+
+ cs->status = r->err_status ? r->err_status : r->headers_out.status;
+
+ if (NULL != r->connection->addr_text.data) {
+ ngx_cpystrn(cs->client, r->connection->addr_text.data,
+ r->connection->addr_text.len >= SCORE__CLIENT_LEN ?
+ SCORE__CLIENT_LEN : (r->connection->addr_text.len + 1));
+ }
+ if (0 < r->headers_in.server.len) {
+ ngx_cpystrn(cs->vhost, r->headers_in.server.data, SCORE__VHOST_LEN <= r->headers_in.server.len ?
+ SCORE__VHOST_LEN : (r->headers_in.server.len + 1));
+ }
+ if (NULL != r->request_line.data) {
+ ngx_cpystrn(cs->request, r->request_line.data, r->request_line.len >= SCORE__REQUEST_LEN ?
+ SCORE__REQUEST_LEN : (r->request_line.len + 1));
+ }
+ }
+#endif
+
ngx_http_log_request(r);
log->action = "closing request";
@@ -3386,6 +3504,11 @@
}
}
+#if (NGX_STAT_EXTENDED)
+ my_worker->mode = SERVER_READY;
+ set_conn_mode(r->connection, SERVER_READY);
+#endif
+
/* the various request strings were allocated from r->pool */
ctx = log->data;
ctx->request = NULL;
@@ -3403,6 +3526,8 @@
r->pool = NULL;
ngx_destroy_pool(pool);
+
+
}
@@ -3443,10 +3568,15 @@
#endif
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
(void) ngx_atomic_fetch_add(ngx_stat_active, -1);
#endif
+#if (NGX_STAT_EXTENDED)
+ set_conn_inactive(c);
+ set_conn_mode(c, SERVER_DEAD);
+#endif
+
c->destroyed = 1;
pool = c->pool;
diff -ur nginx-1.4.2/src/http/ngx_http_request.h nginx-1.4.2_extended_status/src/http/ngx_http_request.h
--- nginx-1.4.2/src/http/ngx_http_request.h 2013-07-17 14:51:22.000000000 +0200
+++ nginx-1.4.2_extended_status/src/http/ngx_http_request.h 2013-07-25 16:24:20.000000000 +0200
@@ -527,7 +527,7 @@
unsigned filter_need_temporary:1;
unsigned allow_ranges:1;
-#if (NGX_STAT_STUB)
+#if (NGX_STAT_STUB || NGX_STAT_EXTENDED)
unsigned stat_reading:1;
unsigned stat_writing:1;
#endif
diff -ur nginx-1.4.2/src/os/unix/ngx_process.c nginx-1.4.2_extended_status/src/os/unix/ngx_process.c
--- nginx-1.4.2/src/os/unix/ngx_process.c 2013-07-17 14:51:22.000000000 +0200
+++ nginx-1.4.2_extended_status/src/os/unix/ngx_process.c 2013-07-25 16:24:20.000000000 +0200
@@ -35,6 +35,10 @@
ngx_int_t ngx_last_process;
ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
+#if (NGX_STAT_EXTENDED)
+ngx_int_t old_ngx_last_process = 0;
+ngx_process_t old_ngx_processes[NGX_MAX_PROCESSES];
+#endif
ngx_signal_t signals[] = {
{ ngx_signal_value(NGX_RECONFIGURE_SIGNAL),
diff -ur nginx-1.4.2/src/os/unix/ngx_process_cycle.c nginx-1.4.2_extended_status/src/os/unix/ngx_process_cycle.c
--- nginx-1.4.2/src/os/unix/ngx_process_cycle.c 2013-07-17 14:51:22.000000000 +0200
+++ nginx-1.4.2_extended_status/src/os/unix/ngx_process_cycle.c 2013-07-25 16:24:20.000000000 +0200
@@ -237,6 +237,15 @@
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reconfiguring");
+#if (NGX_STAT_EXTENDED)
+ old_ngx_last_process = ngx_last_process;
+ for (i = 0; i < old_ngx_last_process; i++)
+ old_ngx_processes[i] = ngx_processes[i];
+
+ ngx_last_process = 0;
+ ngx_process_slot = 0;
+#endif
+
cycle = ngx_init_cycle(cycle);
if (cycle == NULL) {
cycle = (ngx_cycle_t *) ngx_cycle;
@@ -488,6 +497,64 @@
ch.fd = -1;
+#if (NGX_STAT_EXTENDED)
+ if ( NGX_CMD_QUIT == ch.command && 0 < old_ngx_last_process )
+ {
+ for (i = 0; i < old_ngx_last_process; i++) {
+ ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "child: %d %P e:%d t:%d d:%d r:%d j:%d",
+ i,
+ old_ngx_processes[i].pid,
+ old_ngx_processes[i].exiting,
+ old_ngx_processes[i].exited,
+ old_ngx_processes[i].detached,
+ old_ngx_processes[i].respawn,
+ old_ngx_processes[i].just_spawn);
+
+ if (old_ngx_processes[i].detached || old_ngx_processes[i].pid == -1)
+ continue;
+
+ if (old_ngx_processes[i].exiting && signo == ngx_signal_value( NGX_SHUTDOWN_SIGNAL))
+ continue;
+
+ if (ch.command) {
+ if (ngx_write_channel(old_ngx_processes[i].channel[0], &ch, sizeof(ngx_channel_t), cycle->log) == NGX_OK) {
+ if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL))
+ old_ngx_processes[i].exiting = 1;
+
+ continue;
+ }
+ }
+
+ ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
+ "kill (%P, %d)", old_ngx_processes[i].pid, signo);
+
+ if (kill(old_ngx_processes[i].pid, signo) == -1) {
+ err = ngx_errno;
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
+ "kill(%P, %d) failed", old_ngx_processes[i].pid, signo);
+
+ if (err == NGX_ESRCH) {
+ old_ngx_processes[i].exited = 1;
+ old_ngx_processes[i].exiting = 0;
+ ngx_reap = 1;
+ }
+ continue;
+ }
+
+ if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL))
+ old_ngx_processes[i].exiting = 1;
+ }
+
+ old_ngx_last_process = -1;
+
+ for (i = 0; i < ngx_last_process; i++) {
+ ngx_processes [i].just_spawn = 0 ;
+ }
+
+ return ;
+ }
+#endif
for (i = 0; i < ngx_last_process; i++) {
@@ -732,6 +799,21 @@
ngx_setproctitle("worker process");
+#if (NGX_STAT_EXTENDED)
+ {
+ my_worker = (worker_score *) ((char *) workers + WORKER_SCORE_LEN * ngx_process_slot);
+ ngx_time_t *tp = ngx_timeofday();
+
+ my_worker->last_used = tp->sec;
+ my_worker->pid = ngx_getpid();
+ my_worker->bytes_sent = 0L;
+ my_worker->access_count = 0L;
+ my_worker->mode = SERVER_READY;
+
+ times(&my_worker->times);
+ }
+#endif
+
#if (NGX_THREADS)
{
ngx_int_t n;
diff -ur nginx-1.4.2/src/os/unix/ngx_process.h nginx-1.4.2_extended_status/src/os/unix/ngx_process.h
--- nginx-1.4.2/src/os/unix/ngx_process.h 2013-07-17 14:51:22.000000000 +0200
+++ nginx-1.4.2_extended_status/src/os/unix/ngx_process.h 2013-07-25 16:24:20.000000000 +0200
@@ -84,5 +84,9 @@
extern ngx_int_t ngx_last_process;
extern ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
+#if (NGX_STAT_EXTENDED)
+extern ngx_int_t old_ngx_last_process;
+extern ngx_process_t old_ngx_processes[NGX_MAX_PROCESSES];
+#endif
#endif /* _NGX_PROCESS_H_INCLUDED_ */