@@ -3539,6 +3539,34 @@ fn is_timeout(err: &hyper::Error) -> Option<&ProxyCacheError> {
35393539 }
35403540}
35413541
3542+ mod client_counter {
3543+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
3544+
3545+ static CONNECTED_CLIENTS : AtomicUsize = AtomicUsize :: new ( 0 ) ;
3546+
3547+ #[ must_use]
3548+ pub ( crate ) fn connected_clients ( ) -> usize {
3549+ CONNECTED_CLIENTS . load ( Ordering :: Relaxed )
3550+ }
3551+
3552+ pub ( super ) struct ClientCounter {
3553+ _private : ( ) ,
3554+ }
3555+
3556+ impl ClientCounter {
3557+ pub ( super ) fn new ( ) -> Self {
3558+ CONNECTED_CLIENTS . fetch_add ( 1 , Ordering :: Relaxed ) ;
3559+ Self { _private : ( ) }
3560+ }
3561+ }
3562+
3563+ impl Drop for ClientCounter {
3564+ fn drop ( & mut self ) {
3565+ CONNECTED_CLIENTS . fetch_sub ( 1 , Ordering :: Relaxed ) ;
3566+ }
3567+ }
3568+ }
3569+
35423570async fn main_loop ( ) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync > > {
35433571 #[ cfg( feature = "tokio_console" ) ]
35443572 console_subscriber:: init ( ) ;
@@ -3807,6 +3835,8 @@ async fn main_loop() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
38073835 err
38083836 } ) ?;
38093837
3838+ let client_counter = client_counter:: ClientCounter :: new ( ) ;
3839+
38103840 info ! ( "New client connection from {}" , client. ip( ) . to_canonical( ) ) ;
38113841 let client_start = Instant :: now ( ) ;
38123842
@@ -3858,6 +3888,8 @@ async fn main_loop() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
38583888 }
38593889 }
38603890
3891+ drop ( client_counter) ;
3892+
38613893 info ! (
38623894 "Closed connection to {} after {}" ,
38633895 client. ip( ) . to_canonical( ) ,
0 commit comments