fix: add queue_count to metrics

This commit is contained in:
Ruben Fiszel
2023-09-16 02:31:58 +02:00
parent c8bf141cea
commit e54a8013a0
2 changed files with 30 additions and 2 deletions

View File

@@ -8,6 +8,7 @@
use gethostname::gethostname;
use git_version::git_version;
use rand::Rng;
use sqlx::{Pool, Postgres};
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
@@ -201,9 +202,10 @@ Windmill Community Edition {GIT_VERSION}
let mut rx = rx.resubscribe();
let base_internal_url = base_internal_url.to_string();
let rd_delay = rand::thread_rng().gen_range(0..30);
tokio::spawn(async move {
//monitor_db is applied at start, no need to apply it twice
tokio::time::sleep(Duration::from_secs(30)).await;
tokio::time::sleep(Duration::from_secs(rd_delay)).await;
loop {
monitor_db(
&db,

View File

@@ -34,6 +34,12 @@ lazy_static::lazy_static! {
"Total number of jobs deleted due to their ping timing out in an unrecoverable state."
)
.unwrap();
static ref QUEUE_COUNT: prometheus::IntGaugeVec = prometheus::register_int_gauge_vec!(
"queue_count",
"Number of jobs in the queue",
&["tag"]
).unwrap();
}
pub async fn monitor_db<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 'static>(
@@ -66,14 +72,34 @@ pub async fn monitor_db<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
}
}
};
let expose_queue_metrics_f = async {
if *METRICS_ENABLED && server_mode {
expose_queue_metrics(&db).await;
}
};
join!(
expired_items_f,
zombie_jobs_f,
reload_worker_config_f,
reload_custom_tags_f
reload_custom_tags_f,
expose_queue_metrics_f
);
}
pub async fn expose_queue_metrics(db: &Pool<Postgres>) {
let queue_counts = sqlx::query!("SELECT tag, count(*) as count FROM queue GROUP BY tag")
.fetch_all(db)
.await
.ok()
.unwrap_or_else(|| vec![]);
for q in queue_counts {
let count = q.count.unwrap_or(0);
let tag = q.tag;
let metric = (*QUEUE_COUNT).with_label_values(&[&tag]);
metric.set(count as i64);
}
}
pub async fn reload_worker_config(db: &Pool<Postgres>, tx: tokio::sync::broadcast::Sender<()>) {
let config = load_worker_config(&db).await;
if let Err(e) = config {