@@ -580,15 +580,15 @@ impl Collector {
580580 server_info. query_count += stat. value as u64 ;
581581 server_info. application_name = app_name;
582582
583- let pool_stats = address_stat_lookup
583+ let address_stats = address_stat_lookup
584584 . entry ( server_info. address_id )
585585 . or_insert ( HashMap :: default ( ) ) ;
586- let counter = pool_stats
586+ let counter = address_stats
587587 . entry ( "total_query_count" . to_string ( ) )
588588 . or_insert ( 0 ) ;
589589 * counter += stat. value ;
590590
591- let duration = pool_stats
591+ let duration = address_stats
592592 . entry ( "total_query_time" . to_string ( ) )
593593 . or_insert ( 0 ) ;
594594 * duration += duration_ms as i64 ;
@@ -681,26 +681,26 @@ impl Collector {
681681 Some ( server_info) => {
682682 server_info. application_name = app_name;
683683
684- let pool_stats = address_stat_lookup
684+ let address_stats = address_stat_lookup
685685 . entry ( server_info. address_id )
686686 . 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 ) ;
689690 * counter += stat. value ;
690691
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 ( ) ) ;
701698
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 ;
704704 }
705705 }
706706 None => ( ) ,
@@ -903,8 +903,6 @@ impl Collector {
903903 "sv_active" ,
904904 "sv_tested" ,
905905 "sv_login" ,
906- "maxwait" ,
907- "maxwait_us" ,
908906 ] {
909907 pool_stats. insert ( stat. to_string ( ) , 0 ) ;
910908 }
@@ -962,6 +960,12 @@ impl Collector {
962960 LATEST_CLIENT_STATS . store ( Arc :: new ( client_states. clone ( ) ) ) ;
963961 LATEST_SERVER_STATS . store ( Arc :: new ( server_states. clone ( ) ) ) ;
964962 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 ) ;
965969 }
966970
967971 EventName :: UpdateAverages { address_id } => {
0 commit comments