[pdm-devel] [PATCH proxmox-datacenter-manager 24/25] pdm-client: add metric collection API methods
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Feb 13 13:10:34 CET 2025
On Tue, Feb 11, 2025 at 01:05:40PM +0100, Lukas Wagner wrote:
> This adds bindings for collection settings, trigger, and status APIs.
>
> Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
> ---
> lib/pdm-client/src/lib.rs | 87 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 87 insertions(+)
>
> diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs
> index a41b82c..ae41e9a 100644
> --- a/lib/pdm-client/src/lib.rs
> +++ b/lib/pdm-client/src/lib.rs
> @@ -320,6 +320,93 @@ impl<T: HttpApiClient> PdmClient<T> {
> .ok_or_else(|| Error::BadApi("api returned no webauthn entry id".to_string(), None))
> }
>
> + /// Get global metric collection settings.
> + pub async fn get_metric_collection_settings(
> + &self,
> + ) -> Result<pdm_api_types::CollectionSettings, Error> {
> + let path = "/api2/extjs/config/metric-collection/default";
> + Ok(self.0.get(path).await?.expect_json()?.data)
> + }
> +
> + /// Update global metric collection settings.
> + pub async fn update_metric_collection_settings(
> + &self,
> + updater: pdm_api_types::CollectionSettingsUpdater,
> + delete: Option<Vec<pdm_api_types::DeletableCollectionSettingsProperty>>,
> + ) -> Result<(), Error> {
> + let path = "/api2/extjs/config/metric-collection/default";
> +
> + #[derive(Serialize)]
> + struct UpdateSettings<'a> {
> + updater: &'a pdm_api_types::CollectionSettingsUpdater,
> + #[serde(skip_serializing_if = "Option::is_none")]
> + delete: Option<Vec<pdm_api_types::DeletableCollectionSettingsProperty>>,
> + }
> +
> + let params = UpdateSettings {
> + updater: &updater,
> + delete,
> + };
> + self.0.put(path, ¶ms).await?.nodata()?;
> + Ok(())
> + }
> +
> + /// Trigger metric collection for a single remote or all, if no remote is provided.
> + pub async fn trigger_metric_collection(
> + &self,
> + remote: Option<&str>,
> + ) -> Result<(), proxmox_client::Error> {
> + let path = "/api2/extjs/metric-collection/trigger";
> +
> + #[derive(Serialize)]
> + struct TriggerParams<'a> {
> + #[serde(skip_serializing_if = "Option::is_none")]
> + remote: Option<&'a str>,
> + }
> +
> + self.0
> + .post(path, &TriggerParams { remote })
> + .await?
> + .expect_json::<()>()?;
Look like this should be `.nodata()`?
> +
> + Ok(())
> + }
> +
> + /// Get global metric collection status.
> + pub async fn get_metric_collection_status(
> + &self,
> + ) -> Result<Vec<pdm_api_types::MetricCollectionStatus>, Error> {
> + let path = "/api2/extjs/metric-collection/status";
> + Ok(self.0.get(path).await?.expect_json()?.data)
> + }
> +
> + /// Get global metric collection status.
> + pub async fn get_metric_collection_rrddata(
> + &self,
> + mode: RrdMode,
> + timeframe: RrdTimeframe,
> + ) -> Result<pdm_api_types::rrddata::FullCollectionDatapoint, Error> {
> + let mut path = "/api2/extjs/metric-collection/rrddata".to_string();
> + let mut sep = '?';
> + add_query_arg(&mut path, &mut sep, "cf", &Some(mode));
> + add_query_arg(&mut path, &mut sep, "timeframe", &Some(timeframe));
> + Ok(self.0.get(&path).await?.expect_json()?.data)
> + }
> +
> + /// Get per-remote metric collection status.
> + pub async fn get_per_remote_metric_collection_rrddata(
> + &self,
> + remote: &str,
> + mode: RrdMode,
> + timeframe: RrdTimeframe,
> + ) -> Result<pdm_api_types::rrddata::RemoteCollectionDatapoint, Error> {
> + let mut path = format!("/api2/extjs/remotes/{remote}/metric-collection-rrddata");
> + let mut sep = '?';
> + add_query_arg(&mut path, &mut sep, "cf", &Some(mode));
> + add_query_arg(&mut path, &mut sep, "timeframe", &Some(timeframe));
> + Ok(self.0.get(&path).await?.expect_json()?.data)
> + }
> +
> pub async fn pve_list_nodes(
> &self,
> remote: &str,
> --
> 2.39.5
More information about the pdm-devel
mailing list