annotate src/http/modules/ngx_http_stub_status_module.c @ 50:72eb30262aac NGINX_0_1_25

nginx 0.1.25 *) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author Igor Sysoev <http://sysoev.ru>
date Sat, 19 Mar 2005 00:00:00 +0300
parents 4989c3d25945
children b55cbf18157e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 #include <ngx_config.h>
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 #include <ngx_core.h>
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 #include <ngx_http.h>
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 void *conf);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 static ngx_command_t ngx_http_status_commands[] = {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 { ngx_string("stub_status"),
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 ngx_http_set_status,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 0,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 0,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 NULL },
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 ngx_null_command
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 };
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 ngx_http_module_t ngx_http_stub_status_module_ctx = {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 NULL, /* pre conf */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 NULL, /* create main configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 NULL, /* init main configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 NULL, /* create server configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 NULL, /* merge server configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 NULL, /* create location configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 NULL /* merge location configuration */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 };
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 ngx_module_t ngx_http_stub_status_module = {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 NGX_MODULE,
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 &ngx_http_stub_status_module_ctx, /* module context */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 ngx_http_status_commands, /* module directives */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 NGX_HTTP_MODULE, /* module type */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 NULL, /* init module */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 NULL /* init process */
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 };
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48 static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 {
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
50 size_t size;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
51 ngx_int_t rc;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
52 ngx_buf_t *b;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
53 ngx_chain_t out;
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
54 ngx_atomic_int_t ap, hn, ac, rq, rd, wr;
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 return NGX_HTTP_NOT_ALLOWED;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 rc = ngx_http_discard_body(r);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 if (rc != NGX_OK && rc != NGX_AGAIN) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 return rc;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 r->headers_out.content_type = ngx_list_push(&r->headers_out.headers);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 if (r->headers_out.content_type == NULL) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 return NGX_HTTP_INTERNAL_SERVER_ERROR;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 r->headers_out.content_type->key.len = 0;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 r->headers_out.content_type->key.data = NULL;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 r->headers_out.content_type->value.len = sizeof("text/plain") - 1;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 r->headers_out.content_type->value.data = (u_char *) "text/plain";
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 if (r->method == NGX_HTTP_HEAD) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 r->headers_out.status = NGX_HTTP_OK;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 rc = ngx_http_send_header(r);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 return rc;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
86 size = sizeof("Active connections: \n") + NGX_ATOMIC_T_LEN
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 + sizeof("server accepts handled requests\n") - 1
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
88 + 6 + 3 * NGX_ATOMIC_T_LEN
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
89 + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN;
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 44
diff changeset
91 b = ngx_create_temp_buf(r->pool, size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 44
diff changeset
92 if (b == NULL) {
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 return NGX_HTTP_INTERNAL_SERVER_ERROR;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 out.buf = b;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 out.next = NULL;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 ap = *ngx_stat_accepted;
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
100 hn = *ngx_stat_handled;
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101 ac = *ngx_stat_active;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 rq = *ngx_stat_requests;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 rd = *ngx_stat_reading;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 wr = *ngx_stat_writing;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
106 b->last = ngx_sprintf(b->last, "Active connections: %A \n", ac);
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 b->last = ngx_cpymem(b->last, "server accepts handled requests\n",
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 sizeof("server accepts handled requests\n") - 1);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
111 b->last = ngx_sprintf(b->last, " %A %A %A \n", ap, hn, rq);
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112
44
4989c3d25945 nginx 0.1.22
Igor Sysoev <http://sysoev.ru>
parents: 42
diff changeset
113 b->last = ngx_sprintf(b->last, "Reading: %A Writing: %A Waiting: %A \n",
42
41ccba1aba45 nginx 0.1.21
Igor Sysoev <http://sysoev.ru>
parents: 36
diff changeset
114 rd, wr, ac - (rd + wr));
36
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 r->headers_out.status = NGX_HTTP_OK;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 r->headers_out.content_length_n = b->last - b->pos;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 b->last_buf = 1;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 rc = ngx_http_send_header(r);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124 return rc;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 return ngx_http_output_filter(r, &out);;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 }
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 {
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 ngx_http_core_loc_conf_t *clcf;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 clcf->handler = ngx_http_status_handler;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138 return NGX_CONF_OK;
a39d1b793287 nginx 0.1.18
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 }