@@ -39,6 +39,7 @@ use tokio::time::{interval_at, Instant};
3939struct DataStatsItem {
4040 total_request : AtomicU64 ,
4141 total_blocked_request : AtomicU64 ,
42+ total_failed_request : AtomicU64 ,
4243 qps : AtomicU32 ,
4344 qps_count : AtomicU32 ,
4445 request_dropped : AtomicU64 ,
@@ -48,6 +49,7 @@ struct DataStatsItem {
4849struct DataStatsItem {
4950 total_request : Arc < Mutex < u64 > > ,
5051 total_blocked_request : Arc < Mutex < u64 > > ,
52+ total_failed_request : Arc < Mutex < u64 > > ,
5153 qps : AtomicU32 ,
5254 qps_count : AtomicU32 ,
5355 request_dropped : Arc < Mutex < u64 > > ,
@@ -59,6 +61,7 @@ impl DataStatsItem {
5961 let ret = DataStatsItem {
6062 total_request : 0 . into ( ) ,
6163 total_blocked_request : 0 . into ( ) ,
64+ total_failed_request : 0 . into ( ) ,
6265 qps : 0 . into ( ) ,
6366 qps_count : 0 . into ( ) ,
6467 request_dropped : 0 . into ( ) ,
@@ -67,6 +70,7 @@ impl DataStatsItem {
6770 let ret = DataStatsItem {
6871 total_request : Arc :: new ( Mutex :: new ( 0 ) ) ,
6972 total_blocked_request : Arc :: new ( Mutex :: new ( 0 ) ) ,
73+ total_failed_request : Arc :: new ( Mutex :: new ( 0 ) ) ,
7074 qps : 0 . into ( ) ,
7175 qps_count : 0 . into ( ) ,
7276 request_dropped : Arc :: new ( Mutex :: new ( 0 ) ) ,
@@ -154,6 +158,33 @@ impl DataStatsItem {
154158 }
155159 }
156160
161+ pub fn add_total_failed_request ( & self , total : u64 ) {
162+ #[ cfg( target_has_atomic = "64" ) ]
163+ {
164+ self . total_failed_request
165+ . fetch_add ( total, Ordering :: Relaxed ) ;
166+ }
167+
168+ #[ cfg( not( target_has_atomic = "64" ) ) ]
169+ {
170+ let mut total_failed_request = self . total_failed_request . lock ( ) . unwrap ( ) ;
171+ * total_failed_request += total;
172+ }
173+ }
174+
175+ pub fn get_total_failed_request ( & self ) -> u64 {
176+ #[ cfg( target_has_atomic = "64" ) ]
177+ {
178+ return self . total_failed_request . load ( Ordering :: Relaxed ) ;
179+ }
180+
181+ #[ cfg( not( target_has_atomic = "64" ) ) ]
182+ {
183+ let total = self . total_failed_request . lock ( ) . unwrap ( ) ;
184+ return * total;
185+ }
186+ }
187+
157188 #[ allow( dead_code) ]
158189 pub fn get_current_hour_total ( & self ) -> u64 {
159190 return Stats :: get_request_total ( ) ;
@@ -211,6 +242,14 @@ impl DataStats {
211242 self . data . add_total_blocked_request ( total) ;
212243 }
213244
245+ pub fn get_total_failed_request ( & self ) -> u64 {
246+ return self . data . get_total_failed_request ( ) ;
247+ }
248+
249+ pub fn add_total_failed_request ( & self , total : u64 ) {
250+ self . data . add_total_failed_request ( total) ;
251+ }
252+
214253 pub fn get_total_request ( & self ) -> u64 {
215254 return self . data . get_total_request ( ) ;
216255 }
@@ -291,11 +330,24 @@ impl DataStats {
291330 if total_blocked_count == 0 {
292331 let mut parm = DomainListGetParam :: new ( ) ;
293332 parm. is_blocked = Some ( true ) ;
294-
333+
295334 let count = self . db . get_domain_list_count ( Some ( & parm) ) ;
296335 total_blocked_count = count;
297336 }
298337 self . data . add_total_blocked_request ( total_blocked_count) ;
338+
339+ // load total failed request
340+ let mut total_failed_count = 0 as u64 ;
341+ let status_data_total_failed_count = status_data. get ( "total_failed_request" ) ;
342+ if status_data_total_failed_count. is_some ( ) {
343+ let count = status_data_total_failed_count. unwrap ( ) . parse :: < u64 > ( ) ;
344+ if let Ok ( count) = count {
345+ total_failed_count = count;
346+ } else {
347+ total_failed_count = 0 ;
348+ }
349+ }
350+ self . data . add_total_failed_request ( total_failed_count) ;
299351 Ok ( ( ) )
300352 }
301353
@@ -308,6 +360,10 @@ impl DataStats {
308360 "total_blocked_request" ,
309361 self . get_total_blocked_request ( ) . to_string ( ) . as_str ( ) ,
310362 ) ?;
363+ self . db . set_status_data (
364+ "total_failed_request" ,
365+ self . get_total_failed_request ( ) . to_string ( ) . as_str ( ) ,
366+ ) ?;
311367
312368 Ok ( ( ) )
313369 }
@@ -331,7 +387,7 @@ impl DataStats {
331387 . delete_domain_before_timestamp ( now - self . conf . read ( ) . unwrap ( ) . max_log_age_ms as u64 ) ;
332388 if let Err ( e) = ret {
333389 if e. to_string ( ) == "Query returned no rows" {
334- return
390+ return ;
335391 }
336392
337393 dns_log ! (
0 commit comments