@@ -39,6 +39,7 @@ use tokio::time::{interval_at, Instant};
39
39
struct DataStatsItem {
40
40
total_request : AtomicU64 ,
41
41
total_blocked_request : AtomicU64 ,
42
+ total_failed_request : AtomicU64 ,
42
43
qps : AtomicU32 ,
43
44
qps_count : AtomicU32 ,
44
45
request_dropped : AtomicU64 ,
@@ -48,6 +49,7 @@ struct DataStatsItem {
48
49
struct DataStatsItem {
49
50
total_request : Arc < Mutex < u64 > > ,
50
51
total_blocked_request : Arc < Mutex < u64 > > ,
52
+ total_failed_request : Arc < Mutex < u64 > > ,
51
53
qps : AtomicU32 ,
52
54
qps_count : AtomicU32 ,
53
55
request_dropped : Arc < Mutex < u64 > > ,
@@ -59,6 +61,7 @@ impl DataStatsItem {
59
61
let ret = DataStatsItem {
60
62
total_request : 0 . into ( ) ,
61
63
total_blocked_request : 0 . into ( ) ,
64
+ total_failed_request : 0 . into ( ) ,
62
65
qps : 0 . into ( ) ,
63
66
qps_count : 0 . into ( ) ,
64
67
request_dropped : 0 . into ( ) ,
@@ -67,6 +70,7 @@ impl DataStatsItem {
67
70
let ret = DataStatsItem {
68
71
total_request : Arc :: new ( Mutex :: new ( 0 ) ) ,
69
72
total_blocked_request : Arc :: new ( Mutex :: new ( 0 ) ) ,
73
+ total_failed_request : Arc :: new ( Mutex :: new ( 0 ) ) ,
70
74
qps : 0 . into ( ) ,
71
75
qps_count : 0 . into ( ) ,
72
76
request_dropped : Arc :: new ( Mutex :: new ( 0 ) ) ,
@@ -154,6 +158,33 @@ impl DataStatsItem {
154
158
}
155
159
}
156
160
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
+
157
188
#[ allow( dead_code) ]
158
189
pub fn get_current_hour_total ( & self ) -> u64 {
159
190
return Stats :: get_request_total ( ) ;
@@ -211,6 +242,14 @@ impl DataStats {
211
242
self . data . add_total_blocked_request ( total) ;
212
243
}
213
244
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
+
214
253
pub fn get_total_request ( & self ) -> u64 {
215
254
return self . data . get_total_request ( ) ;
216
255
}
@@ -291,11 +330,24 @@ impl DataStats {
291
330
if total_blocked_count == 0 {
292
331
let mut parm = DomainListGetParam :: new ( ) ;
293
332
parm. is_blocked = Some ( true ) ;
294
-
333
+
295
334
let count = self . db . get_domain_list_count ( Some ( & parm) ) ;
296
335
total_blocked_count = count;
297
336
}
298
337
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) ;
299
351
Ok ( ( ) )
300
352
}
301
353
@@ -308,6 +360,10 @@ impl DataStats {
308
360
"total_blocked_request" ,
309
361
self . get_total_blocked_request ( ) . to_string ( ) . as_str ( ) ,
310
362
) ?;
363
+ self . db . set_status_data (
364
+ "total_failed_request" ,
365
+ self . get_total_failed_request ( ) . to_string ( ) . as_str ( ) ,
366
+ ) ?;
311
367
312
368
Ok ( ( ) )
313
369
}
@@ -331,7 +387,7 @@ impl DataStats {
331
387
. delete_domain_before_timestamp ( now - self . conf . read ( ) . unwrap ( ) . max_log_age_ms as u64 ) ;
332
388
if let Err ( e) = ret {
333
389
if e. to_string ( ) == "Query returned no rows" {
334
- return
390
+ return ;
335
391
}
336
392
337
393
dns_log ! (
0 commit comments