From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 1BA2C1FF164 for <inbox@lore.proxmox.com>; Fri, 14 Feb 2025 14:07:22 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F042619C72; Fri, 14 Feb 2025 14:07:20 +0100 (CET) From: Lukas Wagner <l.wagner@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 14 Feb 2025 14:06:42 +0100 Message-Id: <20250214130653.283012-18-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250214130653.283012-1-l.wagner@proxmox.com> References: <20250214130653.283012-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.010 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox-datacenter-manager v2 17/28] metric collection: save time needed for collection run to RRD X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> For large setups, it might be useful to know how much time was needed to collect metrics for *all* remotes together, e.g. for making sure that the collection interval is not exceeded. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> --- .../src/metric_collection/collection_task.rs | 14 +++++ server/src/metric_collection/rrd_task.rs | 53 ++++++++++++++----- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/server/src/metric_collection/collection_task.rs b/server/src/metric_collection/collection_task.rs index b58bf2fc..60c62c87 100644 --- a/server/src/metric_collection/collection_task.rs +++ b/server/src/metric_collection/collection_task.rs @@ -22,6 +22,7 @@ use pdm_api_types::{ }; use pdm_config::metric_collection::COLLECTION_SETTINGS_TYPE; +use crate::metric_collection::rrd_task::CollectionStats; use crate::{connection, task_utils}; use super::{ @@ -97,8 +98,21 @@ impl MetricCollectionTask { ).await; if let Some(remotes) = Self::load_remote_config() { + let now = Instant::now(); let to_fetch = remotes.order.as_slice(); self.fetch_remotes(&remotes, to_fetch).await; + let elapsed = now.elapsed(); + + if let Err(err) = self.metric_data_tx.send( + RrdStoreRequest::CollectionStats { + timestamp: proxmox_time::epoch_i64(), + stats: CollectionStats { + // TODO: use as_millis_f64 once stabilized + total_time: elapsed.as_secs_f64() * 1000. + } + }).await { + log::error!("could not send collection stats to rrd task: {err}"); + } } } diff --git a/server/src/metric_collection/rrd_task.rs b/server/src/metric_collection/rrd_task.rs index a8e48e89..7d0b95b2 100644 --- a/server/src/metric_collection/rrd_task.rs +++ b/server/src/metric_collection/rrd_task.rs @@ -38,6 +38,13 @@ pub(super) enum RrdStoreRequest { /// Timestamp at which the request was done (UNIX epoch). request_at: i64, }, + /// Store collection stats. + CollectionStats { + /// Timestamp at which the collection took place (UNIX epoch). + timestamp: i64, + /// Statistics. + stats: CollectionStats, + }, } /// Result for a [`RrdStoreRequest`]. @@ -46,6 +53,12 @@ pub(super) struct RrdStoreResult { pub(super) most_recent_timestamp: i64, } +/// Statistics for a (full) metric collection run. +pub(super) struct CollectionStats { + /// Total time in ms. + pub(super) total_time: f64, +} + /// Task which stores received metrics in the RRD. Metric data is fed into /// this task via a MPSC channel. pub(super) async fn store_in_rrd_task( @@ -57,7 +70,8 @@ pub(super) async fn store_in_rrd_task( // Involves some blocking file IO let res = tokio::task::spawn_blocking(move || { let mut most_recent_timestamp = 0; - let channel = match msg { + + match msg { RrdStoreRequest::Pve { remote, metrics, @@ -71,7 +85,13 @@ pub(super) async fn store_in_rrd_task( } store_response_time(&cache_clone, &remote, response_time, request_at); - channel + let result = RrdStoreResult { + most_recent_timestamp, + }; + + if channel.send(result).is_err() { + log::error!("could not send RrdStoreStoreResult to metric collection task"); + }; } RrdStoreRequest::Pbs { remote, @@ -86,17 +106,17 @@ pub(super) async fn store_in_rrd_task( } store_response_time(&cache_clone, &remote, response_time, request_at); - channel - } - }; + let result = RrdStoreResult { + most_recent_timestamp, + }; - if channel - .send(RrdStoreResult { - most_recent_timestamp, - }) - .is_err() - { - log::error!("could not send RrdStoreStoreResult to metric collection task"); + if channel.send(result).is_err() { + log::error!("could not send RrdStoreStoreResult to metric collection task"); + }; + } + RrdStoreRequest::CollectionStats { timestamp, stats } => { + store_stats(&cache_clone, &stats, timestamp) + } }; }) .await; @@ -157,6 +177,15 @@ fn store_response_time(cache: &RrdCache, remote_name: &str, response_time: f64, cache.update_value(&name, response_time, timestamp, DataSourceType::Gauge); } +fn store_stats(cache: &RrdCache, stats: &CollectionStats, timestamp: i64) { + cache.update_value( + "local/metric-collection/total-time", + stats.total_time, + timestamp, + DataSourceType::Gauge, + ); +} + #[cfg(test)] mod tests { use proxmox_rrd_api_types::{RrdMode, RrdTimeframe}; -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel