Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_stub_status_module.c @ 5079:1c472e3b8c10
Introduced variables in ngx_http_stub_status module.
Three new variables were added: $connections_active, $connections_reading
and $connections_writing.
author | Andrey Belov <defan@nginx.com> |
---|---|
date | Thu, 21 Feb 2013 23:31:57 +0000 |
parents | 2b6cb7528409 |
children | a29c574d61fa |
comparison
equal
deleted
inserted
replaced
5078:10c74d3b15d1 | 5079:1c472e3b8c10 |
---|---|
7 | 7 |
8 #include <ngx_config.h> | 8 #include <ngx_config.h> |
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 | 11 |
12 | |
13 static ngx_int_t ngx_http_stub_status_variable(ngx_http_request_t *r, | |
14 ngx_http_variable_value_t *v, uintptr_t data); | |
15 static ngx_int_t ngx_http_stub_status_add_variables(ngx_conf_t *cf); | |
12 | 16 |
13 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, | 17 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, |
14 void *conf); | 18 void *conf); |
15 | 19 |
16 static ngx_command_t ngx_http_status_commands[] = { | 20 static ngx_command_t ngx_http_status_commands[] = { |
26 }; | 30 }; |
27 | 31 |
28 | 32 |
29 | 33 |
30 static ngx_http_module_t ngx_http_stub_status_module_ctx = { | 34 static ngx_http_module_t ngx_http_stub_status_module_ctx = { |
31 NULL, /* preconfiguration */ | 35 ngx_http_stub_status_add_variables, /* preconfiguration */ |
32 NULL, /* postconfiguration */ | 36 NULL, /* postconfiguration */ |
33 | 37 |
34 NULL, /* create main configuration */ | 38 NULL, /* create main configuration */ |
35 NULL, /* init main configuration */ | 39 NULL, /* init main configuration */ |
36 | 40 |
56 NULL, /* exit master */ | 60 NULL, /* exit master */ |
57 NGX_MODULE_V1_PADDING | 61 NGX_MODULE_V1_PADDING |
58 }; | 62 }; |
59 | 63 |
60 | 64 |
65 static ngx_http_variable_t ngx_http_stub_status_vars[] = { | |
66 | |
67 { ngx_string("connections_active"), NULL, ngx_http_stub_status_variable, | |
68 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
69 | |
70 { ngx_string("connections_reading"), NULL, ngx_http_stub_status_variable, | |
71 1, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
72 | |
73 { ngx_string("connections_writing"), NULL, ngx_http_stub_status_variable, | |
74 2, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
75 | |
76 { ngx_null_string, NULL, NULL, 0, 0, 0 } | |
77 }; | |
78 | |
79 | |
61 static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r) | 80 static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r) |
62 { | 81 { |
63 size_t size; | 82 size_t size; |
64 ngx_int_t rc; | 83 ngx_int_t rc; |
65 ngx_buf_t *b; | 84 ngx_buf_t *b; |
131 | 150 |
132 return ngx_http_output_filter(r, &out); | 151 return ngx_http_output_filter(r, &out); |
133 } | 152 } |
134 | 153 |
135 | 154 |
155 static ngx_int_t | |
156 ngx_http_stub_status_variable(ngx_http_request_t *r, | |
157 ngx_http_variable_value_t *v, uintptr_t data) | |
158 { | |
159 u_char *p; | |
160 ngx_atomic_int_t value; | |
161 | |
162 p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN); | |
163 if (p == NULL) { | |
164 return NGX_ERROR; | |
165 } | |
166 | |
167 switch (data) { | |
168 case 0: | |
169 value = *ngx_stat_active; | |
170 break; | |
171 | |
172 case 1: | |
173 value = *ngx_stat_reading; | |
174 break; | |
175 | |
176 case 2: | |
177 value = *ngx_stat_writing; | |
178 break; | |
179 | |
180 /* suppress warning */ | |
181 default: | |
182 value = 0; | |
183 break; | |
184 } | |
185 | |
186 v->len = ngx_sprintf(p, "%uA", value) - p; | |
187 v->valid = 1; | |
188 v->no_cacheable = 0; | |
189 v->not_found = 0; | |
190 v->data = p; | |
191 | |
192 return NGX_OK; | |
193 } | |
194 | |
195 | |
196 static ngx_int_t | |
197 ngx_http_stub_status_add_variables(ngx_conf_t *cf) | |
198 { | |
199 ngx_http_variable_t *var, *v; | |
200 | |
201 for (v = ngx_http_stub_status_vars; v->name.len; v++) { | |
202 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
203 if (var == NULL) { | |
204 return NGX_ERROR; | |
205 } | |
206 | |
207 var->get_handler = v->get_handler; | |
208 var->data = v->data; | |
209 } | |
210 | |
211 return NGX_OK; | |
212 } | |
213 | |
214 | |
136 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 215 static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
137 { | 216 { |
138 ngx_http_core_loc_conf_t *clcf; | 217 ngx_http_core_loc_conf_t *clcf; |
139 | 218 |
140 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | 219 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |