9
10
#include <ngx_http.h>
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
17
static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd,
29
34
static ngx_http_module_t ngx_http_stub_status_module_ctx = {
30
NULL, /* preconfiguration */
35
ngx_http_stub_status_add_variables, /* preconfiguration */
31
36
NULL, /* postconfiguration */
33
38
NULL, /* create main configuration */
65
static ngx_http_variable_t ngx_http_stub_status_vars[] = {
67
{ ngx_string("connections_active"), NULL, ngx_http_stub_status_variable,
68
0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
70
{ ngx_string("connections_reading"), NULL, ngx_http_stub_status_variable,
71
1, NGX_HTTP_VAR_NOCACHEABLE, 0 },
73
{ ngx_string("connections_writing"), NULL, ngx_http_stub_status_variable,
74
2, NGX_HTTP_VAR_NOCACHEABLE, 0 },
76
{ ngx_string("connections_waiting"), NULL, ngx_http_stub_status_variable,
77
3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
79
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
60
83
static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
66
ngx_atomic_int_t ap, hn, ac, rq, rd, wr;
89
ngx_atomic_int_t ap, hn, ac, rq, rd, wr, wa;
68
91
if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
69
92
return NGX_HTTP_NOT_ALLOWED;
78
r->headers_out.content_type.len = sizeof("text/plain") - 1;
79
r->headers_out.content_type.data = (u_char *) "text/plain";
101
ngx_str_set(&r->headers_out.content_type, "text/plain");
81
103
if (r->method == NGX_HTTP_HEAD) {
82
104
r->headers_out.status = NGX_HTTP_OK;
116
139
b->last = ngx_sprintf(b->last, " %uA %uA %uA \n", ap, hn, rq);
118
141
b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n",
119
rd, wr, ac - (rd + wr));
121
144
r->headers_out.status = NGX_HTTP_OK;
122
145
r->headers_out.content_length_n = b->last - b->pos;
147
b->last_buf = (r == r->main) ? 1 : 0;
126
149
rc = ngx_http_send_header(r);
160
ngx_http_stub_status_variable(ngx_http_request_t *r,
161
ngx_http_variable_value_t *v, uintptr_t data)
164
ngx_atomic_int_t value;
166
p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN);
173
value = *ngx_stat_active;
177
value = *ngx_stat_reading;
181
value = *ngx_stat_writing;
185
value = *ngx_stat_waiting;
188
/* suppress warning */
194
v->len = ngx_sprintf(p, "%uA", value) - p;
205
ngx_http_stub_status_add_variables(ngx_conf_t *cf)
207
ngx_http_variable_t *var, *v;
209
for (v = ngx_http_stub_status_vars; v->name.len; v++) {
210
var = ngx_http_add_variable(cf, &v->name, v->flags);
215
var->get_handler = v->get_handler;
136
223
static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
138
225
ngx_http_core_loc_conf_t *clcf;