Skip to content

Commit 1485f3f

Browse files
authored
Merge pull request #316 from u5surf/issue-315
Issue 315
2 parents 8027b3b + 7a641fe commit 1485f3f

5 files changed

+35
-1
lines changed

src/ngx_http_vhost_traffic_status_module.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ static ngx_conf_enum_t ngx_http_vhost_traffic_status_average_method_post[] = {
5959
{ ngx_null_string, 0 }
6060
};
6161

62+
static ngx_conf_bitmask_t ngx_http_vhost_traffic_status_ignore_status_masks[] = {
63+
{ ngx_string("1xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_1XX },
64+
{ ngx_string("2xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_2XX },
65+
{ ngx_string("3xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_3XX },
66+
{ ngx_string("4xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_4XX },
67+
{ ngx_string("5xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_5XX },
68+
{ ngx_string("off"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_OFF },
69+
{ ngx_null_string, 0 }
70+
};
6271

6372
static ngx_command_t ngx_http_vhost_traffic_status_commands[] = {
6473

@@ -217,6 +226,13 @@ static ngx_command_t ngx_http_vhost_traffic_status_commands[] = {
217226
offsetof(ngx_http_vhost_traffic_status_loc_conf_t, stats_by_upstream),
218227
NULL },
219228

229+
{ ngx_string("vhost_traffic_status_ignore_status"),
230+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
231+
ngx_conf_set_bitmask_slot,
232+
NGX_HTTP_LOC_CONF_OFFSET,
233+
offsetof(ngx_http_vhost_traffic_status_loc_conf_t, ignore_status),
234+
&ngx_http_vhost_traffic_status_ignore_status_masks },
235+
220236
ngx_null_command
221237
};
222238

@@ -1031,6 +1047,8 @@ ngx_http_vhost_traffic_status_merge_loc_conf(ngx_conf_t *cf, void *parent, void
10311047
ngx_conf_merge_value(conf->bypass_stats, prev->bypass_stats, 0);
10321048

10331049
ngx_conf_merge_value(conf->stats_by_upstream, prev->stats_by_upstream, 1);
1050+
ngx_conf_merge_bitmask_value(conf->ignore_status, prev->ignore_status,
1051+
(NGX_CONF_BITMASK_SET|NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_OFF));
10341052

10351053
name = ctx->shm_name;
10361054

src/ngx_http_vhost_traffic_status_module.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_AVG_PERIOD 60
5656
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_DUMP_PERIOD 60
5757

58+
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_OFF 0x0002
59+
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_1XX 0x0004
60+
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_2XX 0x0008
61+
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_3XX 0x0010
62+
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_4XX 0x0020
63+
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_5XX 0x0040
64+
5865
#define ngx_http_vhost_traffic_status_add_rc(s, n) { \
5966
if(s < 200) {n->stat_1xx_counter++;} \
6067
else if(s < 300) {n->stat_2xx_counter++;} \
@@ -63,6 +70,8 @@
6370
else {n->stat_5xx_counter++;} \
6471
}
6572

73+
#define ngx_http_vhost_traffic_status_ignore_status(i, s) ( (((i & (1<<2)) && 100 <= s && s < 200) || ((i & (1<<3)) && 200 <= s && s < 300) || ((i & (1<<4)) && 300 <= s && s < 400) || ((i & (1<<5)) && 400 <= s && s < 500) || ((i & (1<<6)) && 500 <= s && s < 600)) ? 1 : 0)
74+
6675
#if (NGX_HTTP_CACHE)
6776

6877
#if !defined(nginx_version) || nginx_version < 1005007
@@ -298,6 +307,7 @@ typedef struct {
298307
ngx_flag_t bypass_stats;
299308

300309
ngx_flag_t stats_by_upstream;
310+
ngx_uint_t ignore_status;
301311

302312
ngx_rbtree_node_t **node_caches;
303313
} ngx_http_vhost_traffic_status_loc_conf_t;

src/ngx_http_vhost_traffic_status_node.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ ngx_http_vhost_traffic_status_node_set(ngx_http_request_t *r,
362362

363363
ovtsn = *vtsn;
364364

365+
vtsn->ignore_status = vtscf->ignore_status;
365366
ms = ngx_http_vhost_traffic_status_request_time(r);
366367
ngx_http_vhost_traffic_status_node_update(r, vtsn, ms);
367368

@@ -379,6 +380,10 @@ ngx_http_vhost_traffic_status_node_update(ngx_http_request_t *r,
379380
{
380381
ngx_uint_t status = r->headers_out.status;
381382

383+
if (ngx_http_vhost_traffic_status_ignore_status(vtsn->ignore_status, status)) {
384+
return;
385+
}
386+
382387
vtsn->stat_request_counter++;
383388
vtsn->stat_in_bytes += (ngx_atomic_uint_t) r->request_length;
384389
vtsn->stat_out_bytes += (ngx_atomic_uint_t) r->connection->sent;

src/ngx_http_vhost_traffic_status_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_QUEUE_LEN 64
1212
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_BUCKET_LEN 32
1313

14-
1514
typedef struct {
1615
ngx_msec_t time;
1716
ngx_msec_int_t msec;
@@ -101,6 +100,7 @@ typedef struct {
101100

102101
ngx_http_vhost_traffic_status_node_upstream_t stat_upstream;
103102
size_t len;
103+
ngx_uint_t ignore_status;
104104
u_char data[1];
105105
} ngx_http_vhost_traffic_status_node_t;
106106

src/ngx_http_vhost_traffic_status_shm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ ngx_http_vhost_traffic_status_shm_add_node(ngx_http_request_t *r,
149149

150150
node->key = hash;
151151
vtsn->len = key->len;
152+
vtsn->ignore_status = vtscf->ignore_status;
152153
ngx_http_vhost_traffic_status_node_init(r, vtsn);
153154
vtsn->stat_upstream.type = type;
154155
ngx_memcpy(vtsn->data, key->data, key->len);

0 commit comments

Comments
 (0)