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 67D2A1FF164 for <inbox@lore.proxmox.com>; Fri, 14 Feb 2025 14:08:13 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F30551A033; Fri, 14 Feb 2025 14:08:13 +0100 (CET) From: Lukas Wagner <l.wagner@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 14 Feb 2025 14:06:47 +0100 Message-Id: <20250214130653.283012-23-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 22/28] api: add api for querying metric collection RRD data 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 commit adds two new API endpoints: - remotes/{id}/metric-collection-rrddata - metric-collection/rrddata The first one returns graphable datapoints for the API response time when fetching metrics, the second one datapoints about the total time needed for collecting *all* remotes. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> --- lib/pdm-api-types/src/rrddata.rs | 26 +++++++++++++ server/src/api/metric_collection.rs | 60 ++++++++++++++++++++++++++--- server/src/api/remotes.rs | 53 +++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 5 deletions(-) diff --git a/lib/pdm-api-types/src/rrddata.rs b/lib/pdm-api-types/src/rrddata.rs index a973977c..7559243c 100644 --- a/lib/pdm-api-types/src/rrddata.rs +++ b/lib/pdm-api-types/src/rrddata.rs @@ -216,3 +216,29 @@ pub struct PbsDatastoreDataPoint { #[serde(skip_serializing_if = "Option::is_none")] pub disk_write: Option<f64>, } + +#[api] +#[derive(Serialize, Deserialize, Default)] +#[serde(rename_all = "kebab-case")] +/// RRD datapoint for statistics about the metric collection loop. +pub struct FullCollectionDatapoint { + /// Timestamp (UNIX epoch) + pub time: u64, + + /// Total time in milliseconds needed for full metric collection run. + #[serde(skip_serializing_if = "Option::is_none")] + pub total_time: Option<f64>, +} + +#[api] +#[derive(Serialize, Deserialize, Default)] +#[serde(rename_all = "kebab-case")] +/// RRD datapoint for metric collection from a single remote. +pub struct RemoteCollectionDatapoint { + /// Timestamp (UNIX epoch) + pub time: u64, + + /// API response time in milliseconds when requesting the metrics from the remote. + #[serde(skip_serializing_if = "Option::is_none")] + pub response_time: Option<f64>, +} diff --git a/server/src/api/metric_collection.rs b/server/src/api/metric_collection.rs index 1a9e0e28..22736cb0 100644 --- a/server/src/api/metric_collection.rs +++ b/server/src/api/metric_collection.rs @@ -1,17 +1,27 @@ use anyhow::Error; -use pdm_api_types::remotes::REMOTE_ID_SCHEMA; use proxmox_router::{Router, SubdirMap}; +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 super::rrd_common::{self, DataPoint}; + pub const ROUTER: Router = Router::new().subdirs(SUBDIRS); #[sortable] -const SUBDIRS: SubdirMap = &sorted!([( - "trigger", - &Router::new().post(&API_METHOD_TRIGGER_METRIC_COLLECTION) -),]); +const SUBDIRS: SubdirMap = &sorted!([ + ( + "trigger", + &Router::new().post(&API_METHOD_TRIGGER_METRIC_COLLECTION) + ), + ( + "rrddata", + &Router::new().get(&API_METHOD_GET_METRIC_COLLECTION_RRD_DATA) + ), +]); #[api( input: { @@ -33,3 +43,43 @@ pub async fn trigger_metric_collection(remote: Option<String>) -> Result<(), Err Ok(()) } + +impl DataPoint for FullCollectionDatapoint { + fn new(time: u64) -> Self { + Self { + time, + ..Default::default() + } + } + + fn fields() -> &'static [&'static str] { + &["total-time"] + } + + fn set_field(&mut self, name: &str, value: f64) { + if name == "total-time" { + self.total_time = Some(value); + } + } +} + +#[api( + input: { + properties: { + timeframe: { + type: RrdTimeframe, + }, + cf: { + type: RrdMode, + }, + }, + }, +)] +/// Read metric collection RRD data. +fn get_metric_collection_rrd_data( + timeframe: RrdTimeframe, + cf: RrdMode, +) -> Result<Vec<FullCollectionDatapoint>, Error> { + let base = "local/metric-collection"; + rrd_common::create_datapoints_from_rrd(base, timeframe, cf) +} diff --git a/server/src/api/remotes.rs b/server/src/api/remotes.rs index 27b91cfe..bbb24b26 100644 --- a/server/src/api/remotes.rs +++ b/server/src/api/remotes.rs @@ -9,6 +9,8 @@ use proxmox_access_control::CachedUserInfo; use proxmox_router::{ http_bail, http_err, list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap, }; +use proxmox_rrd_api_types::RrdMode; +use proxmox_rrd_api_types::RrdTimeframe; use proxmox_schema::api; use proxmox_schema::Schema; use proxmox_section_config::typed::SectionConfigData; @@ -16,12 +18,15 @@ use proxmox_sortable_macro::sortable; use proxmox_time::{epoch_i64, epoch_to_rfc2822}; use pdm_api_types::remotes::{Remote, RemoteType, RemoteUpdater, REMOTE_ID_SCHEMA}; +use pdm_api_types::rrddata::RemoteCollectionDatapoint; use pdm_api_types::{Authid, ConfigDigest, PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_MODIFY}; use crate::metric_collection; use crate::{connection, pbs_client}; use super::pve; +use super::rrd_common; +use super::rrd_common::DataPoint; pub const ROUTER: Router = Router::new() .get(&API_METHOD_LIST_REMOTES) @@ -38,6 +43,10 @@ const ITEM_ROUTER: Router = Router::new() const SUBDIRS: SubdirMap = &sorted!([ ("config", &Router::new().get(&API_METHOD_REMOTE_CONFIG)), ("version", &Router::new().get(&API_METHOD_VERSION)), + ( + "metric-collection-rrddata", + &Router::new().get(&API_METHOD_GET_PER_REMOTE_METRIC_COLLECTION_RRD_DATA) + ), ]); pub fn get_remote<'a>( @@ -331,3 +340,47 @@ pub fn remote_config(id: String) -> Result<Remote, Error> { remote.token = String::new(); // mask token in response Ok(remote.clone()) } + +impl DataPoint for RemoteCollectionDatapoint { + fn new(time: u64) -> Self { + Self { + time, + ..Default::default() + } + } + + fn fields() -> &'static [&'static str] { + &["response-time"] + } + + fn set_field(&mut self, name: &str, value: f64) { + if name == "response-time" { + self.response_time = Some(value); + } + } +} + +#[api( + input: { + properties: { + id: { + schema: REMOTE_ID_SCHEMA, + }, + timeframe: { + type: RrdTimeframe, + }, + cf: { + type: RrdMode, + }, + }, + }, +)] +/// Read metric collection RRD data. +fn get_per_remote_metric_collection_rrd_data( + id: String, + timeframe: RrdTimeframe, + cf: RrdMode, +) -> Result<Vec<RemoteCollectionDatapoint>, Error> { + let base = format!("local/metric-collection/remotes/{id}"); + rrd_common::create_datapoints_from_rrd(&base, timeframe, cf) +} -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel