Ticket #1242: diff.txt

File diff.txt, 7.2 KB (added by sergey.smitienko@…, 9 years ago)

git diff

Line 
1diff --git a/auto/modules b/auto/modules
2index be3561e..55c75ca 100644
3--- a/auto/modules
4+++ b/auto/modules
5@@ -878,6 +878,11 @@ if [ $HTTP = YES ]; then
6 ngx_module_link=$HTTP_STUB_STATUS
7
8 . auto/module
9+
10+ if [ $NGX_STAT_STUB_EXTENDED = YES ]; then
11+ have=NGX_STAT_STUB_EXTENDED . auto/have
12+ fi
13+
14 fi
15 fi
16
17diff --git a/auto/options b/auto/options
18index 66b822a..f2a1a88 100644
19--- a/auto/options
20+++ b/auto/options
21@@ -105,6 +105,7 @@ HTTP_UPSTREAM_ZONE=YES
22
23 # STUB
24 HTTP_STUB_STATUS=NO
25+NGX_STAT_STUB_EXTENDED=NO
26
27 MAIL=NO
28 MAIL_SSL=NO
29@@ -279,6 +280,7 @@ $0: warning: the \"--with-ipv6\" option is deprecated"
30
31 # STUB
32 --with-http_stub_status_module) HTTP_STUB_STATUS=YES ;;
33+ --with-http_stub_status_extended) NGX_STAT_STUB_EXTENDED=YES ;;
34
35 --with-mail) MAIL=YES ;;
36 --with-mail=dynamic) MAIL=DYNAMIC ;;
37@@ -567,6 +569,7 @@ cat << END
38 --with-openssl-opt=OPTIONS set additional build options for OpenSSL
39
40 --with-debug enable debug logging
41+ --with-http_stub_status_extended enable extended status codes statistics
42
43 END
44
45diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
46index 57af813..e702e72 100644
47--- a/src/event/ngx_event.c
48+++ b/src/event/ngx_event.c
49@@ -74,6 +74,13 @@ ngx_atomic_t *ngx_stat_writing = &ngx_stat_writing0;
50 static ngx_atomic_t ngx_stat_waiting0;
51 ngx_atomic_t *ngx_stat_waiting = &ngx_stat_waiting0;
52
53+#if (NGX_STAT_STUB_EXTENDED)
54+
55+static ngx_stat_ext_t ngx_stat_ext0[NGX_STAT_EXT_SIZE];
56+ngx_stat_ext_t *ngx_stat_ext = &ngx_stat_ext0[0];
57+
58+#endif
59+
60 #endif
61
62
63@@ -497,6 +504,9 @@ ngx_event_module_init(ngx_cycle_t *cycle)
64 + cl /* ngx_stat_writing */
65 + cl; /* ngx_stat_waiting */
66
67+#if (NGX_STAT_STUB_EXTENDED)
68+ size += sizeof (ngx_stat_ext_t) * NGX_STAT_EXT_SIZE;
69+#endif
70 #endif
71
72 shm.size = size;
73@@ -543,6 +553,74 @@ ngx_event_module_init(ngx_cycle_t *cycle)
74 ngx_stat_writing = (ngx_atomic_t *) (shared + 8 * cl);
75 ngx_stat_waiting = (ngx_atomic_t *) (shared + 9 * cl);
76
77+
78+#if (NGX_STAT_STUB_EXTENDED)
79+ ngx_stat_ext = (ngx_stat_ext_t*) (shared + 10 * cl);
80+
81+ /*codes we are interested in*/
82+ ngx_stat_ext[0].code = 0; /* default */
83+ ngx_stat_ext[1].code = 100;
84+ ngx_stat_ext[2].code = 101;
85+ ngx_stat_ext[3].code = 102;
86+ ngx_stat_ext[4].code = 200;
87+ ngx_stat_ext[5].code = 201;
88+ ngx_stat_ext[6].code = 202;
89+ ngx_stat_ext[7].code = 203;
90+ ngx_stat_ext[8].code = 204;
91+ ngx_stat_ext[9].code = 205;
92+ ngx_stat_ext[10].code = 206;
93+ ngx_stat_ext[11].code = 207;
94+ ngx_stat_ext[12].code = 300;
95+ ngx_stat_ext[13].code = 301;
96+ ngx_stat_ext[14].code = 302;
97+ ngx_stat_ext[15].code = 303;
98+ ngx_stat_ext[16].code = 304;
99+ ngx_stat_ext[17].code = 305;
100+ ngx_stat_ext[18].code = 307;
101+ ngx_stat_ext[19].code = 400;
102+ ngx_stat_ext[20].code = 401;
103+ ngx_stat_ext[21].code = 402;
104+ ngx_stat_ext[22].code = 403;
105+ ngx_stat_ext[23].code = 404;
106+ ngx_stat_ext[24].code = 405;
107+ ngx_stat_ext[25].code = 406;
108+ ngx_stat_ext[26].code = 407;
109+ ngx_stat_ext[27].code = 408;
110+ ngx_stat_ext[28].code = 409;
111+ ngx_stat_ext[29].code = 410;
112+ ngx_stat_ext[30].code = 411;
113+ ngx_stat_ext[31].code = 412;
114+ ngx_stat_ext[32].code = 413;
115+ ngx_stat_ext[33].code = 414;
116+ ngx_stat_ext[34].code = 415;
117+ ngx_stat_ext[35].code = 416;
118+ ngx_stat_ext[36].code = 417;
119+ ngx_stat_ext[37].code = 422;
120+ ngx_stat_ext[38].code = 423;
121+ ngx_stat_ext[39].code = 424;
122+ ngx_stat_ext[40].code = 425;
123+ ngx_stat_ext[41].code = 426;
124+ ngx_stat_ext[42].code = 428;
125+ ngx_stat_ext[43].code = 429;
126+ ngx_stat_ext[44].code = 431;
127+ ngx_stat_ext[45].code = 434;
128+ ngx_stat_ext[46].code = 444;
129+ ngx_stat_ext[47].code = 449;
130+ ngx_stat_ext[48].code = 451;
131+ ngx_stat_ext[49].code = 500;
132+ ngx_stat_ext[50].code = 501;
133+ ngx_stat_ext[51].code = 502;
134+ ngx_stat_ext[52].code = 503;
135+ ngx_stat_ext[53].code = 504;
136+ ngx_stat_ext[54].code = 505;
137+ ngx_stat_ext[55].code = 506;
138+ ngx_stat_ext[56].code = 507;
139+ ngx_stat_ext[57].code = 508;
140+ ngx_stat_ext[58].code = 509;
141+ ngx_stat_ext[59].code = 510;
142+ ngx_stat_ext[60].code = 511;
143+#endif
144+
145 #endif
146
147 return NGX_OK;
148diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
149index 053bd16..9503430 100644
150--- a/src/event/ngx_event.h
151+++ b/src/event/ngx_event.h
152@@ -485,6 +485,17 @@ extern ngx_atomic_t *ngx_stat_reading;
153 extern ngx_atomic_t *ngx_stat_writing;
154 extern ngx_atomic_t *ngx_stat_waiting;
155
156+#if (NGX_STAT_STUB_EXTENDED)
157+
158+typedef struct {
159+ ngx_uint_t code;
160+ ngx_atomic_t counter;
161+} ngx_stat_ext_t;
162+
163+extern ngx_stat_ext_t *ngx_stat_ext;
164+#define NGX_STAT_EXT_SIZE 61
165+
166+#endif
167 #endif
168
169
170diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
171index 61199f2..6b60328 100644
172--- a/src/http/modules/ngx_http_stub_status_module.c
173+++ b/src/http/modules/ngx_http_stub_status_module.c
174@@ -1,4 +1,3 @@
175-
176 /*
177 * Copyright (C) Igor Sysoev
178 * Copyright (C) Nginx, Inc.
179@@ -88,6 +87,7 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
180 ngx_buf_t *b;
181 ngx_chain_t out;
182 ngx_atomic_int_t ap, hn, ac, rq, rd, wr, wa;
183+ int i;
184
185 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
186 return NGX_HTTP_NOT_ALLOWED;
187@@ -118,6 +118,12 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
188 + 6 + 3 * NGX_ATOMIC_T_LEN
189 + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN;
190
191+#if (NGX_STAT_STUB_EXTENDED)
192+
193+ size += NGX_STAT_EXT_SIZE * (sizeof("status_code_: \n") + 4 + NGX_ATOMIC_T_LEN);
194+
195+#endif
196+
197 b = ngx_create_temp_buf(r->pool, size);
198 if (b == NULL) {
199 return NGX_HTTP_INTERNAL_SERVER_ERROR;
200@@ -144,6 +150,15 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
201 b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n",
202 rd, wr, wa);
203
204+#if (NGX_STAT_STUB_EXTENDED)
205+
206+ b->last = ngx_sprintf(b->last, "status_code_def: %uA\n", ngx_stat_ext[0].counter);
207+ for (i = 1; i < NGX_STAT_EXT_SIZE; i++) {
208+ b->last = ngx_sprintf(b->last, "status_code_%uA: %uA\n", ngx_stat_ext[i].code, ngx_stat_ext[i].counter);
209+ }
210+
211+#endif
212+
213 r->headers_out.status = NGX_HTTP_OK;
214 r->headers_out.content_length_n = b->last - b->pos;
215
216diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
217index 476f039..8b058fe 100644
218--- a/src/http/ngx_http_request.c
219+++ b/src/http/ngx_http_request.c
220@@ -1,4 +1,3 @@
221-
222 /*
223 * Copyright (C) Igor Sysoev
224 * Copyright (C) Nginx, Inc.
225@@ -3529,6 +3528,21 @@ ngx_http_log_request(ngx_http_request_t *r)
226 for (i = 0; i < n; i++) {
227 log_handler[i](r);
228 }
229+
230+#if (NGX_STAT_STUB_EXTENDED)
231+
232+ if (r == r->main) {
233+ for (i = 1; i < NGX_STAT_EXT_SIZE; i++) {
234+ if (ngx_stat_ext[i].code == r->headers_out.status) {
235+ (void) ngx_atomic_fetch_add(&ngx_stat_ext[i].counter, 1);
236+ return;
237+ }
238+ }
239+ (void) ngx_atomic_fetch_add(&ngx_stat_ext[0].counter, 1);
240+ }
241+
242+#endif
243+
244 }
245
246