Skip to content

Issue 315 #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/ngx_http_vhost_traffic_status_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ static ngx_conf_enum_t ngx_http_vhost_traffic_status_average_method_post[] = {
{ ngx_null_string, 0 }
};

static ngx_conf_bitmask_t ngx_http_vhost_traffic_status_ignore_status_masks[] = {
{ ngx_string("1xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_1XX },
{ ngx_string("2xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_2XX },
{ ngx_string("3xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_3XX },
{ ngx_string("4xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_4XX },
{ ngx_string("5xx"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_5XX },
{ ngx_string("off"), NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_OFF },
{ ngx_null_string, 0 }
};

static ngx_command_t ngx_http_vhost_traffic_status_commands[] = {

Expand Down Expand Up @@ -217,6 +226,13 @@ static ngx_command_t ngx_http_vhost_traffic_status_commands[] = {
offsetof(ngx_http_vhost_traffic_status_loc_conf_t, stats_by_upstream),
NULL },

{ ngx_string("vhost_traffic_status_ignore_status"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
ngx_conf_set_bitmask_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_vhost_traffic_status_loc_conf_t, ignore_status),
&ngx_http_vhost_traffic_status_ignore_status_masks },

ngx_null_command
};

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

ngx_conf_merge_value(conf->stats_by_upstream, prev->stats_by_upstream, 1);
ngx_conf_merge_bitmask_value(conf->ignore_status, prev->ignore_status,
(NGX_CONF_BITMASK_SET|NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_OFF));

name = ctx->shm_name;

Expand Down
10 changes: 10 additions & 0 deletions src/ngx_http_vhost_traffic_status_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_AVG_PERIOD 60
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_DUMP_PERIOD 60

#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_OFF 0x0002
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_1XX 0x0004
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_2XX 0x0008
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_3XX 0x0010
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_4XX 0x0020
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_IGNORE_STATUS_5XX 0x0040

#define ngx_http_vhost_traffic_status_add_rc(s, n) { \
if(s < 200) {n->stat_1xx_counter++;} \
else if(s < 300) {n->stat_2xx_counter++;} \
Expand All @@ -63,6 +70,8 @@
else {n->stat_5xx_counter++;} \
}

#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)

#if (NGX_HTTP_CACHE)

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

ngx_flag_t stats_by_upstream;
ngx_uint_t ignore_status;

ngx_rbtree_node_t **node_caches;
} ngx_http_vhost_traffic_status_loc_conf_t;
Expand Down
5 changes: 5 additions & 0 deletions src/ngx_http_vhost_traffic_status_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ ngx_http_vhost_traffic_status_node_set(ngx_http_request_t *r,

ovtsn = *vtsn;

vtsn->ignore_status = vtscf->ignore_status;
ms = ngx_http_vhost_traffic_status_request_time(r);
ngx_http_vhost_traffic_status_node_update(r, vtsn, ms);

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

if (ngx_http_vhost_traffic_status_ignore_status(vtsn->ignore_status, status)) {
return;
}

vtsn->stat_request_counter++;
vtsn->stat_in_bytes += (ngx_atomic_uint_t) r->request_length;
vtsn->stat_out_bytes += (ngx_atomic_uint_t) r->connection->sent;
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_http_vhost_traffic_status_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_QUEUE_LEN 64
#define NGX_HTTP_VHOST_TRAFFIC_STATUS_DEFAULT_BUCKET_LEN 32


typedef struct {
ngx_msec_t time;
ngx_msec_int_t msec;
Expand Down Expand Up @@ -101,6 +100,7 @@ typedef struct {

ngx_http_vhost_traffic_status_node_upstream_t stat_upstream;
size_t len;
ngx_uint_t ignore_status;
u_char data[1];
} ngx_http_vhost_traffic_status_node_t;

Expand Down
1 change: 1 addition & 0 deletions src/ngx_http_vhost_traffic_status_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ ngx_http_vhost_traffic_status_shm_add_node(ngx_http_request_t *r,

node->key = hash;
vtsn->len = key->len;
vtsn->ignore_status = vtscf->ignore_status;
ngx_http_vhost_traffic_status_node_init(r, vtsn);
vtsn->stat_upstream.type = type;
ngx_memcpy(vtsn->data, key->data, key->len);
Expand Down