comparison src/http/modules/ngx_http_limit_req_module.c @ 3185:30570a5b9bb0

limit_req_log_level
author Igor Sysoev <igor@sysoev.ru>
date Tue, 06 Oct 2009 10:14:21 +0000
parents b87542338ac3
children 30f841e2536d
comparison
equal deleted inserted replaced
3184:88f972ffe96e 3185:30570a5b9bb0
40 40
41 typedef struct { 41 typedef struct {
42 ngx_shm_zone_t *shm_zone; 42 ngx_shm_zone_t *shm_zone;
43 /* integer value, 1 corresponds to 0.001 r/s */ 43 /* integer value, 1 corresponds to 0.001 r/s */
44 ngx_uint_t burst; 44 ngx_uint_t burst;
45 ngx_uint_t nodelay;/* unsigned nodelay:1 */ 45 ngx_uint_t limit_log_level;
46 ngx_uint_t delay_log_level;
47
48 ngx_uint_t nodelay; /* unsigned nodelay:1 */
46 } ngx_http_limit_req_conf_t; 49 } ngx_http_limit_req_conf_t;
47 50
48 51
49 static void ngx_http_limit_req_delay(ngx_http_request_t *r); 52 static void ngx_http_limit_req_delay(ngx_http_request_t *r);
50 static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_conf_t *lrcf, 53 static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_conf_t *lrcf,
60 static char *ngx_http_limit_req(ngx_conf_t *cf, ngx_command_t *cmd, 63 static char *ngx_http_limit_req(ngx_conf_t *cf, ngx_command_t *cmd,
61 void *conf); 64 void *conf);
62 static ngx_int_t ngx_http_limit_req_init(ngx_conf_t *cf); 65 static ngx_int_t ngx_http_limit_req_init(ngx_conf_t *cf);
63 66
64 67
68 static ngx_conf_enum_t ngx_http_limit_req_log_levels[] = {
69 { ngx_string("info"), NGX_LOG_INFO },
70 { ngx_string("notice"), NGX_LOG_NOTICE },
71 { ngx_string("warn"), NGX_LOG_WARN },
72 { ngx_string("error"), NGX_LOG_ERR },
73 { ngx_null_string, 0 }
74 };
75
76
65 static ngx_command_t ngx_http_limit_req_commands[] = { 77 static ngx_command_t ngx_http_limit_req_commands[] = {
66 78
67 { ngx_string("limit_req_zone"), 79 { ngx_string("limit_req_zone"),
68 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3, 80 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3,
69 ngx_http_limit_req_zone, 81 ngx_http_limit_req_zone,
75 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123, 87 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
76 ngx_http_limit_req, 88 ngx_http_limit_req,
77 NGX_HTTP_LOC_CONF_OFFSET, 89 NGX_HTTP_LOC_CONF_OFFSET,
78 0, 90 0,
79 NULL }, 91 NULL },
92
93 { ngx_string("limit_req_log_level"),
94 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
95 ngx_conf_set_enum_slot,
96 NGX_HTTP_LOC_CONF_OFFSET,
97 offsetof(ngx_http_limit_req_conf_t, limit_log_level),
98 &ngx_http_limit_req_log_levels },
80 99
81 ngx_null_command 100 ngx_null_command
82 }; 101 };
83 102
84 103
184 "limit_req: %i %ui.%03ui", rc, excess / 1000, excess % 1000); 203 "limit_req: %i %ui.%03ui", rc, excess / 1000, excess % 1000);
185 204
186 if (rc == NGX_BUSY) { 205 if (rc == NGX_BUSY) {
187 ngx_shmtx_unlock(&ctx->shpool->mutex); 206 ngx_shmtx_unlock(&ctx->shpool->mutex);
188 207
189 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 208 ngx_log_error(lrcf->limit_log_level, r->connection->log, 0,
190 "limiting requests, excess: %ui.%03ui by zone \"%V\"", 209 "limiting requests, excess: %ui.%03ui by zone \"%V\"",
191 excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name); 210 excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
192 211
193 return NGX_HTTP_SERVICE_UNAVAILABLE; 212 return NGX_HTTP_SERVICE_UNAVAILABLE;
194 } 213 }
198 217
199 if (lrcf->nodelay) { 218 if (lrcf->nodelay) {
200 return NGX_DECLINED; 219 return NGX_DECLINED;
201 } 220 }
202 221
203 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, 222 ngx_log_error(lrcf->delay_log_level, r->connection->log, 0,
204 "delaying request, excess: %ui.%03ui, by zone \"%V\"", 223 "delaying request, excess: %ui.%03ui, by zone \"%V\"",
205 excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name); 224 excess / 1000, excess % 1000, &lrcf->shm_zone->shm.name);
206 225
207 if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) { 226 if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
208 return NGX_HTTP_INTERNAL_SERVER_ERROR; 227 return NGX_HTTP_INTERNAL_SERVER_ERROR;
547 * conf->shm_zone = NULL; 566 * conf->shm_zone = NULL;
548 * conf->burst = 0; 567 * conf->burst = 0;
549 * conf->nodelay = 0; 568 * conf->nodelay = 0;
550 */ 569 */
551 570
571 conf->limit_log_level = NGX_CONF_UNSET_UINT;
572
552 return conf; 573 return conf;
553 } 574 }
554 575
555 576
556 static char * 577 static char *
560 ngx_http_limit_req_conf_t *conf = child; 581 ngx_http_limit_req_conf_t *conf = child;
561 582
562 if (conf->shm_zone == NULL) { 583 if (conf->shm_zone == NULL) {
563 *conf = *prev; 584 *conf = *prev;
564 } 585 }
586
587 ngx_conf_merge_uint_value(conf->limit_log_level, prev->limit_log_level,
588 NGX_LOG_ERR);
589
590 conf->delay_log_level = (conf->limit_log_level == NGX_LOG_INFO) ?
591 NGX_LOG_INFO : conf->limit_log_level + 1;
565 592
566 return NGX_CONF_OK; 593 return NGX_CONF_OK;
567 } 594 }
568 595
569 596