Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
transmit idle connections metrics both for redis and pg pools
Browse files Browse the repository at this point in the history
  • Loading branch information
khodzha committed Aug 27, 2020
1 parent b40776c commit 59c36db
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/app/endpoint/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ pub(crate) enum Metric {
OutgoingQueueEvents(MetricValue),
#[serde(rename(serialize = "apps.conference.db_connections_total"))]
DbConnections(MetricValue),
#[serde(rename(serialize = "apps.event.redis_connections_total"))]
#[serde(rename(serialize = "apps.conference.idle_db_connections_total"))]
IdleDbConnections(MetricValue),
#[serde(rename(serialize = "apps.conference.redis_connections_total"))]
RedisConnections(MetricValue),
#[serde(rename(serialize = "apps.conference.idle_redis_connections_total"))]
IdleRedisConnections(MetricValue),
}

pub(crate) struct PullHandler;
Expand Down Expand Up @@ -102,15 +106,26 @@ impl EventHandler for PullHandler {
vec![]
};

let db_state = context.db().state();
metrics.push(Metric::DbConnections(MetricValue {
value: context.db().state().connections as u64,
value: db_state.connections as u64,
timestamp: now,
}));

metrics.push(Metric::IdleDbConnections(MetricValue {
value: db_state.idle_connections as u64,
timestamp: now,
}));

if let Some(pool) = context.redis_pool() {
let connections = pool.state().connections as u64;
let pool_state = pool.state();
metrics.push(Metric::RedisConnections(MetricValue {
value: connections,
value: pool_state.connections as u64,
timestamp: now,
}));

metrics.push(Metric::IdleRedisConnections(MetricValue {
value: pool_state.idle_connections as u64,
timestamp: now,
}));
}
Expand Down

0 comments on commit 59c36db

Please sign in to comment.