Mercurial > hg > nginx-vendor-0-6
comparison src/http/modules/ngx_http_stub_status_module.c @ 36:a39d1b793287 NGINX_0_1_18
nginx 0.1.18
*) Workaround: the default values of the devpoll_events and the
devpoll_changes directives changed from 512 to 32 to be compatible
with Solaris 10.
*) Bugfix: the proxy_set_x_var and fastcgi_set_var directives were not
inherited.
*) Bugfix: in the redirect rewrite directive the arguments were
concatenated with URI by the "&" rather than the "?".
*) Bugfix: the lines without trailing ";" in the file being included by
the ngx_http_geo_module were silently ignored.
*) Feature: the ngx_http_stub_status_module.
*) Bugfix: the unknown log format in the access_log directive caused
the segmentation fault.
*) Feature: the new "document_root" parameter of the fastcgi_params
directive.
*) Feature: the fastcgi_redirect_errors directive.
*) Feature: the new "break" modifier of the "rewrite" directive allows
to stop the rewrite/location cycle and sets the current
configuration to the request.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 09 Feb 2005 00:00:00 +0300 |
parents | |
children | 41ccba1aba45 |
comparison
equal
deleted
inserted
replaced
35:ef53675fe4a6 | 36:a39d1b793287 |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 #include <ngx_core.h> | |
4 #include <ngx_http.h> | |
5 | |
6 | |
7 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, | |
8 void *conf); | |
9 | |
10 static ngx_command_t ngx_http_status_commands[] = { | |
11 | |
12 { ngx_string("stub_status"), | |
13 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
14 ngx_http_set_status, | |
15 0, | |
16 0, | |
17 NULL }, | |
18 | |
19 ngx_null_command | |
20 }; | |
21 | |
22 | |
23 | |
24 ngx_http_module_t ngx_http_stub_status_module_ctx = { | |
25 NULL, /* pre conf */ | |
26 | |
27 NULL, /* create main configuration */ | |
28 NULL, /* init main configuration */ | |
29 | |
30 NULL, /* create server configuration */ | |
31 NULL, /* merge server configuration */ | |
32 | |
33 NULL, /* create location configuration */ | |
34 NULL /* merge location configuration */ | |
35 }; | |
36 | |
37 | |
38 ngx_module_t ngx_http_stub_status_module = { | |
39 NGX_MODULE, | |
40 &ngx_http_stub_status_module_ctx, /* module context */ | |
41 ngx_http_status_commands, /* module directives */ | |
42 NGX_HTTP_MODULE, /* module type */ | |
43 NULL, /* init module */ | |
44 NULL /* init process */ | |
45 }; | |
46 | |
47 | |
48 static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r) | |
49 { | |
50 size_t size; | |
51 ngx_int_t rc; | |
52 uint32_t ap, hn, ac, rq, rd, wr; | |
53 ngx_buf_t *b; | |
54 ngx_chain_t out; | |
55 | |
56 if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) { | |
57 return NGX_HTTP_NOT_ALLOWED; | |
58 } | |
59 | |
60 rc = ngx_http_discard_body(r); | |
61 | |
62 if (rc != NGX_OK && rc != NGX_AGAIN) { | |
63 return rc; | |
64 } | |
65 | |
66 r->headers_out.content_type = ngx_list_push(&r->headers_out.headers); | |
67 if (r->headers_out.content_type == NULL) { | |
68 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
69 } | |
70 | |
71 r->headers_out.content_type->key.len = 0; | |
72 r->headers_out.content_type->key.data = NULL; | |
73 r->headers_out.content_type->value.len = sizeof("text/plain") - 1; | |
74 r->headers_out.content_type->value.data = (u_char *) "text/plain"; | |
75 | |
76 if (r->method == NGX_HTTP_HEAD) { | |
77 r->headers_out.status = NGX_HTTP_OK; | |
78 | |
79 rc = ngx_http_send_header(r); | |
80 | |
81 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
82 return rc; | |
83 } | |
84 } | |
85 | |
86 size = sizeof("Active connections: \n") + NGX_INT32_LEN | |
87 + sizeof("server accepts handled requests\n") - 1 | |
88 + 6 + 3 * NGX_INT32_LEN | |
89 + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_INT32_LEN; | |
90 | |
91 if (!(b = ngx_create_temp_buf(r->pool, size))) { | |
92 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
93 } | |
94 | |
95 out.buf = b; | |
96 out.next = NULL; | |
97 | |
98 ap = *ngx_stat_accepted; | |
99 hn = *ngx_connection_counter; | |
100 ac = *ngx_stat_active; | |
101 rq = *ngx_stat_requests; | |
102 rd = *ngx_stat_reading; | |
103 wr = *ngx_stat_writing; | |
104 | |
105 b->last = ngx_sprintf(b->last, "Active connections: %d \n", ac); | |
106 | |
107 b->last = ngx_cpymem(b->last, "server accepts handled requests\n", | |
108 sizeof("server accepts handled requests\n") - 1); | |
109 | |
110 b->last = ngx_sprintf(b->last, " %d %d %d \n", ap, hn, rq); | |
111 | |
112 b->last = ngx_sprintf(b->last, "Reading: %d Writing: %d Waiting: %d \n", | |
113 rd, wr, ac - (rd + wr)); | |
114 | |
115 r->headers_out.status = NGX_HTTP_OK; | |
116 r->headers_out.content_length_n = b->last - b->pos; | |
117 | |
118 b->last_buf = 1; | |
119 | |
120 rc = ngx_http_send_header(r); | |
121 | |
122 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
123 return rc; | |
124 } | |
125 | |
126 return ngx_http_output_filter(r, &out);; | |
127 } | |
128 | |
129 | |
130 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
131 { | |
132 ngx_http_core_loc_conf_t *clcf; | |
133 | |
134 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
135 clcf->handler = ngx_http_status_handler; | |
136 | |
137 return NGX_CONF_OK; | |
138 } |