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 [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id BAD6B1FF164 for <inbox@lore.proxmox.com>; Fri, 14 Feb 2025 14:07:52 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 496AE19F3B; Fri, 14 Feb 2025 14:07:52 +0100 (CET) From: Lukas Wagner <l.wagner@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 14 Feb 2025 14:06:48 +0100 Message-Id: <20250214130653.283012-24-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.140 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 POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes 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 23/28] api: metric-collection: add status endpoint 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> This adds a new API endpoint at /metric-collection/status, returning the status of the last metric collection attempt from each remote. For now, this contains the timestamp (last-collected) and any error that occurred (error). Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> --- lib/pdm-api-types/src/metric_collection.rs | 15 +++++++++++++++ server/src/api/metric_collection.rs | 16 +++++++++++++++- server/src/metric_collection/mod.rs | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/pdm-api-types/src/metric_collection.rs b/lib/pdm-api-types/src/metric_collection.rs index 92487d6c..a1157897 100644 --- a/lib/pdm-api-types/src/metric_collection.rs +++ b/lib/pdm-api-types/src/metric_collection.rs @@ -186,3 +186,18 @@ impl CollectionSettings { .unwrap_or(DEFAULT_MIN_CONNECTION_DELAY) } } + +#[api] +#[derive(Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +/// Per-remote collection status. +pub struct MetricCollectionStatus { + /// The remote's name. + pub remote: String, + /// Any error that occured during the last collection attempt. + #[serde(skip_serializing_if = "Option::is_none")] + pub error: Option<String>, + /// Timestamp of last successful collection. + #[serde(skip_serializing_if = "Option::is_none")] + pub last_collection: Option<i64>, +} diff --git a/server/src/api/metric_collection.rs b/server/src/api/metric_collection.rs index 22736cb0..a8243296 100644 --- a/server/src/api/metric_collection.rs +++ b/server/src/api/metric_collection.rs @@ -5,7 +5,11 @@ use proxmox_rrd_api_types::{RrdMode, RrdTimeframe}; use proxmox_schema::api; use proxmox_sortable_macro::sortable; -use pdm_api_types::{remotes::REMOTE_ID_SCHEMA, rrddata::FullCollectionDatapoint}; +use pdm_api_types::{ + remotes::REMOTE_ID_SCHEMA, rrddata::FullCollectionDatapoint, MetricCollectionStatus, +}; + +use crate::metric_collection; use super::rrd_common::{self, DataPoint}; @@ -21,6 +25,10 @@ const SUBDIRS: SubdirMap = &sorted!([ "rrddata", &Router::new().get(&API_METHOD_GET_METRIC_COLLECTION_RRD_DATA) ), + ( + "status", + &Router::new().get(&API_METHOD_GET_METRIC_COLLECTION_STATUS) + ), ]); #[api( @@ -83,3 +91,9 @@ fn get_metric_collection_rrd_data( let base = "local/metric-collection"; rrd_common::create_datapoints_from_rrd(base, timeframe, cf) } + +#[api] +/// Read metric collection RRD data. +fn get_metric_collection_status() -> Result<Vec<MetricCollectionStatus>, Error> { + metric_collection::get_status() +} diff --git a/server/src/metric_collection/mod.rs b/server/src/metric_collection/mod.rs index 5b6c14d2..65ceb4b3 100644 --- a/server/src/metric_collection/mod.rs +++ b/server/src/metric_collection/mod.rs @@ -7,6 +7,8 @@ use tokio::sync::mpsc::{self, Sender}; use proxmox_sys::fs::CreateOptions; +use pdm_api_types::MetricCollectionStatus; + mod collection_task; pub mod rrd_cache; mod rrd_task; @@ -87,3 +89,23 @@ pub async fn trigger_metric_collection() -> Result<(), Error> { Ok(()) } + +/// Get each remote's metric collection status. +pub fn get_status() -> Result<Vec<MetricCollectionStatus>, Error> { + let (remotes, _) = pdm_config::remotes::config()?; + let state = collection_task::load_state()?; + + let mut result = Vec::new(); + + for remote in remotes.order { + if let Some(status) = state.get_status(&remote) { + result.push(MetricCollectionStatus { + remote, + error: status.error.clone(), + last_collection: status.last_collection, + }) + } + } + + Ok(result) +} -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel