@@ -580,15 +580,15 @@ impl Collector {
580
580
server_info. query_count += stat. value as u64 ;
581
581
server_info. application_name = app_name;
582
582
583
- let pool_stats = address_stat_lookup
583
+ let address_stats = address_stat_lookup
584
584
. entry ( server_info. address_id )
585
585
. or_insert ( HashMap :: default ( ) ) ;
586
- let counter = pool_stats
586
+ let counter = address_stats
587
587
. entry ( "total_query_count" . to_string ( ) )
588
588
. or_insert ( 0 ) ;
589
589
* counter += stat. value ;
590
590
591
- let duration = pool_stats
591
+ let duration = address_stats
592
592
. entry ( "total_query_time" . to_string ( ) )
593
593
. or_insert ( 0 ) ;
594
594
* duration += duration_ms as i64 ;
@@ -681,26 +681,26 @@ impl Collector {
681
681
Some ( server_info) => {
682
682
server_info. application_name = app_name;
683
683
684
- let pool_stats = address_stat_lookup
684
+ let address_stats = address_stat_lookup
685
685
. entry ( server_info. address_id )
686
686
. or_insert ( HashMap :: default ( ) ) ;
687
- let counter =
688
- pool_stats. entry ( "total_wait_time" . to_string ( ) ) . or_insert ( 0 ) ;
687
+ let counter = address_stats
688
+ . entry ( "total_wait_time" . to_string ( ) )
689
+ . or_insert ( 0 ) ;
689
690
* counter += stat. value ;
690
691
691
- let counter = pool_stats. entry ( "maxwait_us" . to_string ( ) ) . or_insert ( 0 ) ;
692
- let mic_part = stat. value % 1_000_000 ;
693
-
694
- // Report max time here
695
- if mic_part > * counter {
696
- * counter = mic_part;
697
- }
698
-
699
- let counter = pool_stats. entry ( "maxwait" . to_string ( ) ) . or_insert ( 0 ) ;
700
- let seconds = * counter / 1_000_000 ;
692
+ let pool_stats = pool_stat_lookup
693
+ . entry ( (
694
+ server_info. pool_name . clone ( ) ,
695
+ server_info. username . clone ( ) ,
696
+ ) )
697
+ . or_insert ( HashMap :: default ( ) ) ;
701
698
702
- if seconds > * counter {
703
- * counter = seconds;
699
+ // We record max wait in microseconds, we do the pgbouncer second/microsecond split on admin
700
+ let old_microseconds =
701
+ pool_stats. entry ( "maxwait_us" . to_string ( ) ) . or_insert ( 0 ) ;
702
+ if stat. value > * old_microseconds {
703
+ * old_microseconds = stat. value ;
704
704
}
705
705
}
706
706
None => ( ) ,
@@ -903,8 +903,6 @@ impl Collector {
903
903
"sv_active" ,
904
904
"sv_tested" ,
905
905
"sv_login" ,
906
- "maxwait" ,
907
- "maxwait_us" ,
908
906
] {
909
907
pool_stats. insert ( stat. to_string ( ) , 0 ) ;
910
908
}
@@ -962,6 +960,12 @@ impl Collector {
962
960
LATEST_CLIENT_STATS . store ( Arc :: new ( client_states. clone ( ) ) ) ;
963
961
LATEST_SERVER_STATS . store ( Arc :: new ( server_states. clone ( ) ) ) ;
964
962
LATEST_POOL_STATS . store ( Arc :: new ( pool_stat_lookup. clone ( ) ) ) ;
963
+
964
+ // Clear maxwait after reporting
965
+ pool_stat_lookup
966
+ . entry ( ( pool_name. clone ( ) , username. clone ( ) ) )
967
+ . or_insert ( HashMap :: default ( ) )
968
+ . insert ( "maxwait_us" . to_string ( ) , 0 ) ;
965
969
}
966
970
967
971
EventName :: UpdateAverages { address_id } => {
0 commit comments