@@ -59,9 +59,13 @@ ngx_http_vhost_traffic_status_display_set_server_node(
5959{
6060 u_char * p , * c ;
6161 ngx_int_t rc ;
62+ ngx_uint_t i ;
6263 ngx_str_t tmp , dst ;
64+ ngx_uint_t * status_codes ;
6365 ngx_http_vhost_traffic_status_loc_conf_t * vtscf ;
66+ ngx_http_vhost_traffic_status_ctx_t * ctx ;
6467
68+ ctx = ngx_http_get_module_main_conf (r , ngx_http_vhost_traffic_status_module );
6569 vtscf = ngx_http_get_module_loc_conf (r , ngx_http_vhost_traffic_status_module );
6670
6771 tmp = * key ;
@@ -91,17 +95,42 @@ ngx_http_vhost_traffic_status_display_set_server_node(
9195 "display_set_server_node::escape_json_pool() failed" );
9296 }
9397
94- #if (NGX_HTTP_CACHE )
9598 ngx_http_vhost_traffic_status_display_encode_uri (r , & dst );
96- buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER ,
97- & dst , vtsn -> stat_request_counter ,
98- vtsn -> stat_in_bytes ,
99- vtsn -> stat_out_bytes ,
100- vtsn -> stat_1xx_counter ,
101- vtsn -> stat_2xx_counter ,
102- vtsn -> stat_3xx_counter ,
103- vtsn -> stat_4xx_counter ,
104- vtsn -> stat_5xx_counter ,
99+
100+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_START ,
101+ & dst , vtsn -> stat_request_counter ,
102+ vtsn -> stat_in_bytes ,
103+ vtsn -> stat_out_bytes );
104+
105+ if (ctx -> measure_status_codes != NULL && vtsn -> stat_status_code_counter != NULL ) {
106+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_STATUS_CODE_START );
107+
108+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_OTHER_STATUS_CODE ,
109+ vtsn -> stat_status_code_counter [0 ]);
110+
111+ status_codes = (ngx_uint_t * ) ctx -> measure_status_codes -> elts ;
112+
113+ for (i = 0 ; i < ctx -> measure_status_codes -> nelts ; i ++ ) {
114+ if (vtsn -> stat_status_code_counter [i + 1 ] == 0 && ctx -> measure_all_status_codes ) {
115+ continue ;
116+ }
117+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_STATUS_CODE ,
118+ status_codes [i ], vtsn -> stat_status_code_counter [i + 1 ]);
119+ }
120+
121+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_STATUS_CODE_END );
122+ }
123+
124+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_MIDDLE ,
125+ vtsn -> stat_1xx_counter ,
126+ vtsn -> stat_2xx_counter ,
127+ vtsn -> stat_3xx_counter ,
128+ vtsn -> stat_4xx_counter ,
129+ vtsn -> stat_5xx_counter );
130+
131+
132+ #if (NGX_HTTP_CACHE )
133+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_END ,
105134 vtsn -> stat_cache_miss_counter ,
106135 vtsn -> stat_cache_bypass_counter ,
107136 vtsn -> stat_cache_expired_counter ,
@@ -141,16 +170,7 @@ ngx_http_vhost_traffic_status_display_set_server_node(
141170 vtsn -> stat_cache_scarce_counter_oc ,
142171 vtsn -> stat_request_time_counter_oc );
143172#else
144- ngx_http_vhost_traffic_status_display_encode_uri (r , & dst );
145- buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER ,
146- & dst , vtsn -> stat_request_counter ,
147- vtsn -> stat_in_bytes ,
148- vtsn -> stat_out_bytes ,
149- vtsn -> stat_1xx_counter ,
150- vtsn -> stat_2xx_counter ,
151- vtsn -> stat_3xx_counter ,
152- vtsn -> stat_4xx_counter ,
153- vtsn -> stat_5xx_counter ,
173+ buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_SERVER_END ,
154174 vtsn -> stat_request_time_counter ,
155175 ngx_http_vhost_traffic_status_node_time_queue_average (
156176 & vtsn -> stat_request_times , vtscf -> average_method ,
@@ -217,6 +237,12 @@ ngx_http_vhost_traffic_status_display_set_server(ngx_http_request_t *r,
217237 & vtscf -> stats .stat_request_times ,
218238 & vtsn -> stat_request_times , vtscf -> average_period );
219239
240+ if (ctx -> measure_status_codes != NULL && vtsn -> stat_status_code_counter != NULL ) {
241+ ngx_http_vhost_traffic_status_status_code_merge (
242+ vtscf -> stats .stat_status_code_counter ,
243+ vtsn -> stat_status_code_counter , ctx -> measure_status_codes -> nelts + 1 );
244+ }
245+
220246 vtscf -> stats .stat_request_counter_oc += vtsn -> stat_request_counter_oc ;
221247 vtscf -> stats .stat_in_bytes_oc += vtsn -> stat_in_bytes_oc ;
222248 vtscf -> stats .stat_out_bytes_oc += vtsn -> stat_out_bytes_oc ;
@@ -855,6 +881,11 @@ ngx_http_vhost_traffic_status_display_set(ngx_http_request_t *r,
855881 ngx_memzero (& vtscf -> stats , sizeof (vtscf -> stats ));
856882 ngx_http_vhost_traffic_status_node_time_queue_init (& vtscf -> stats .stat_request_times );
857883
884+ if (ctx -> measure_status_codes != NULL ) {
885+ vtscf -> stats .stat_status_code_counter = ngx_pcalloc (r -> pool , sizeof (ngx_atomic_t ) * (ctx -> measure_status_codes -> nelts + 1 ));
886+ vtscf -> stats .stat_status_code_length = ctx -> measure_status_codes -> nelts ;
887+ }
888+
858889 /* main & connections */
859890 buf = ngx_sprintf (buf , NGX_HTTP_VHOST_TRAFFIC_STATUS_JSON_FMT_S );
860891
0 commit comments