Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include a hostname tag w/ pool metrics #627

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::{fmt::Debug, time::Duration};
use cadence::{Gauged, StatsdClient};
use futures::future::{self, LocalBoxFuture, TryFutureExt};
use lazy_static::lazy_static;
use mozsvc_common::get_hostname;
use serde::Deserialize;
use url::Url;

Expand Down Expand Up @@ -269,23 +270,27 @@ pub fn spawn_pool_periodic_reporter(
interval: Duration,
metrics: StatsdClient,
pool: Box<dyn DbPool>,
) {
) -> Result<(), DbError> {
let hostname = get_hostname().ok_or_else(|| DbError::internal("Couldn't get_hostname"))?;
actix_rt::spawn(async move {
loop {
let results::PoolState {
connections,
idle_connections,
} = pool.state();
metrics
.gauge(
.gauge_with_tags(
"storage.pool.connections.active",
(connections - idle_connections) as u64,
)
.ok();
.with_tag("hostname", &hostname)
.send();
metrics
.gauge("storage.pool.connections.idle", idle_connections as u64)
.ok();
.gauge_with_tags("storage.pool.connections.idle", idle_connections as u64)
.with_tag("hostname", &hostname)
.send();
actix_rt::time::delay_for(interval).await;
}
});
Ok(())
}
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Server {
let secrets = Arc::new(settings.master_secret);
let port = settings.port;

spawn_pool_periodic_reporter(Duration::from_secs(10), metrics.clone(), db_pool.clone());
spawn_pool_periodic_reporter(Duration::from_secs(10), metrics.clone(), db_pool.clone())?;

let server = HttpServer::new(move || {
// Setup the server state
Expand Down