Skip to content

Commit d0f0916

Browse files
committed
Added concurrent db connections
1 parent 02d3407 commit d0f0916

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/web/metrics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ lazy_static::lazy_static! {
7171
"Number of attempted and failed connections to the database"
7272
)
7373
.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();
7480
}
7581

7682
pub fn metrics_handler(req: &mut Request) -> IronResult<Response> {
@@ -87,6 +93,9 @@ pub fn metrics_handler(req: &mut Request) -> IronResult<Response> {
8793
.get(0),
8894
);
8995

96+
let pool = extension!(req, Pool);
97+
CONCURRENT_DB_CONNECTIONS.set(pool.connections() as i64);
98+
9099
let mut buffer = Vec::new();
91100
let families = prometheus::gather();
92101
ctry!(TextEncoder::new().encode(&families, &mut buffer));

src/web/pool.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ impl Pool {
4242
)),
4343
}
4444
}
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+
}
4554
}
4655

4756
impl typemap::Key for Pool {

0 commit comments

Comments
 (0)