File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,12 @@ lazy_static::lazy_static! {
71
71
"Number of attempted and failed connections to the database"
72
72
)
73
73
. unwrap( ) ;
74
+
75
+ pub static ref CONCURRENT_DB_CONNECTIONS : IntGauge = register_int_gauge!(
76
+ "docsrs_db_connections" ,
77
+ "The number of currently used database connections"
78
+ )
79
+ . unwrap( ) ;
74
80
}
75
81
76
82
pub fn metrics_handler ( req : & mut Request ) -> IronResult < Response > {
@@ -87,6 +93,9 @@ pub fn metrics_handler(req: &mut Request) -> IronResult<Response> {
87
93
. get ( 0 ) ,
88
94
) ;
89
95
96
+ let pool = extension ! ( req, Pool ) ;
97
+ CONCURRENT_DB_CONNECTIONS . set ( pool. connections ( ) as i64 ) ;
98
+
90
99
let mut buffer = Vec :: new ( ) ;
91
100
let families = prometheus:: gather ( ) ;
92
101
ctry ! ( TextEncoder :: new( ) . encode( & families, & mut buffer) ) ;
Original file line number Diff line number Diff line change @@ -42,6 +42,15 @@ impl Pool {
42
42
) ) ,
43
43
}
44
44
}
45
+
46
+ pub ( crate ) fn connections ( & self ) -> u32 {
47
+ match self {
48
+ Self :: R2D2 ( conn) => conn. state ( ) . connections ,
49
+
50
+ #[ cfg( test) ]
51
+ Self :: Simple ( ..) => 0 ,
52
+ }
53
+ }
45
54
}
46
55
47
56
impl typemap:: Key for Pool {
You can’t perform that action at this time.
0 commit comments