diff --git a/Cargo.toml b/Cargo.toml index 33d0ff8..1dde3aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,6 @@ package.categories = ["virtualization"] members = [ "xcp-metrics", "xcp-metrics-common", - #"xapi-rs", - #"xcp-metrics-test", - #"plugins/xcp-metrics-plugin-common", "plugins/xcp-metrics-plugin-xen", "plugins/xcp-metrics-plugin-xenstore", "xcp-metrics-tools", diff --git a/plugins/xcp-metrics-plugin-bridge-v2/Cargo.toml b/plugins/xcp-metrics-plugin-bridge-v2/Cargo.toml deleted file mode 100644 index d637ddc..0000000 --- a/plugins/xcp-metrics-plugin-bridge-v2/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "xcp-metrics-plugin-bridge-v2" -edition = "2021" -version.workspace = true -repository.workspace = true -categories.workspace = true -license = "AGPL-3.0-only" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -xcp-metrics-common = { path = "../../xcp-metrics-common" } -xcp-metrics-plugin-common = { path = "../xcp-metrics-plugin-common" } -xapi = { path = "../../xapi-rs" } - -uuid = "1.4" -anyhow = "1.0" -fastrand = "2.0" -serde_json = "1.0" - -tracing = "0.1" -tracing-subscriber = "0.3" - -tokio = { version = "1", features = ["full"] } - -[dependencies.clap] -version = "4.3" -features = ["derive"] diff --git a/plugins/xcp-metrics-plugin-bridge-v2/src/main.rs b/plugins/xcp-metrics-plugin-bridge-v2/src/main.rs deleted file mode 100644 index 1575742..0000000 --- a/plugins/xcp-metrics-plugin-bridge-v2/src/main.rs +++ /dev/null @@ -1,109 +0,0 @@ -use std::{collections::HashMap, path::PathBuf, time::Duration}; - -use clap::{command, Parser}; -use tokio::time; -use xapi::METRICS_SHM_PATH; -use xcp_metrics_common::{ - metrics::MetricSet, - protocol_v3::{self, ProtocolV3Header}, - utils::mapping::CustomMapping, -}; - -use xcp_metrics_plugin_common::{bridge::v3_to_v2::BridgeToV2, protocol_v2::RrddPlugin}; - -/// A bridge plugin (from v3 to v2) for protocol v3 plugins. -#[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] -struct Args { - /// Name of the plugin to bridge. - #[arg(short, long)] - plugin_name: String, - - /// Logging level - #[arg(short, long, default_value_t = tracing::Level::INFO)] - log_level: tracing::Level, - - /// Target daemon path. - #[arg(short, long)] - target: Option, - - /// V3 to V2 mapping file (JSON format) - #[arg(short, long)] - mapping_path: Option, -} - -fn load_mapping(args: &Args) -> HashMap, CustomMapping> { - if let Some(path) = &args.mapping_path { - let content = std::fs::read_to_string(path).expect("Unable to read mapping file"); - serde_json::from_str(&content).expect("Invalid mapping file.") - } else { - Default::default() - } -} - -async fn read_protocol_v3(path: &str) -> anyhow::Result<(ProtocolV3Header, MetricSet)> { - let mut reader = tokio::fs::File::open(path).await?; - - Ok(protocol_v3::parse_v3_async(&mut reader).await?) -} - -#[tokio::main] -async fn main() { - let args = Args::parse(); - - let text_subscriber = tracing_subscriber::fmt() - .with_ansi(true) - .with_max_level(args.log_level) - .compact() - .finish(); - - tracing::subscriber::set_global_default(text_subscriber).unwrap(); - - let bridged_plugin_name = format!("{}_bridged", args.plugin_name); - - let path = format!("{METRICS_SHM_PATH}{}", args.plugin_name); - tracing::info!("Plugin to bridge path: {path}"); - - let (header, metrics_set) = read_protocol_v3(&path).await.unwrap(); - - tracing::debug!("Protocol v3 header: {header:?}"); - tracing::debug!("Initial MetricsSet: {metrics_set:?}"); - - let mut bridge = BridgeToV2::with_mappings(load_mapping(&args)); - bridge.update(metrics_set); - - let mut plugin = RrddPlugin::new( - &bridged_plugin_name, - bridge.get_metadata().clone(), - Some(&bridge.get_data()), - Some( - &args - .target - .unwrap_or_else(|| xapi::get_module_path("xcp-rrdd")), - ), - ) - .await - .unwrap(); - - // Expose protocol v2 - loop { - let (header, metrics_set) = read_protocol_v3(&path).await.unwrap(); - tracing::debug!("Updated: {header:?}"); - tracing::debug!(" - {metrics_set:?}"); - - // Update sources - if bridge.update(metrics_set) { - tracing::debug!("Updating metadata"); - let metadata = bridge.get_metadata().clone(); - tracing::debug!(" - {metadata:?}"); - - plugin - .reset_metadata(metadata, Some(&bridge.get_data())) - .await - .unwrap(); - } - - plugin.update_values(&bridge.get_data()).await.unwrap(); - time::sleep(Duration::from_secs(1)).await; - } -} diff --git a/plugins/xcp-metrics-plugin-common/Cargo.toml b/plugins/xcp-metrics-plugin-common/Cargo.toml deleted file mode 100644 index ca67257..0000000 --- a/plugins/xcp-metrics-plugin-common/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "xcp-metrics-plugin-common" -description = "Library that helps making plugins for xcp-metrics and xcp-rrdd" -version.workspace = true -license = "AGPL-3.0-only" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -xcp-metrics-common = { path = "../../xcp-metrics-common" } -xapi = { path = "../../xapi-rs" } - -anyhow = "1.0" -tokio = "1" -uuid = "1.11" -tracing = "0.1" -tracing-subscriber = "0.3" - -dashmap = "6.1" -futures = "0.3" - -xenstore-rs = "0.8" \ No newline at end of file diff --git a/plugins/xcp-metrics-plugin-common/src/bridge/mod.rs b/plugins/xcp-metrics-plugin-common/src/bridge/mod.rs deleted file mode 100644 index b2cff8d..0000000 --- a/plugins/xcp-metrics-plugin-common/src/bridge/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Bridges for conversion beteen protocol v2 and protocol v3. - -pub mod v3_to_v2; diff --git a/plugins/xcp-metrics-plugin-common/src/bridge/v3_to_v2.rs b/plugins/xcp-metrics-plugin-common/src/bridge/v3_to_v2.rs deleted file mode 100644 index aee6559..0000000 --- a/plugins/xcp-metrics-plugin-common/src/bridge/v3_to_v2.rs +++ /dev/null @@ -1,143 +0,0 @@ -//! Adapter to convert from protocol v3 to protocol v2. -use std::{collections::HashMap, iter}; - -use xcp_metrics_common::{ - metrics::{Label, Metric, MetricFamily, MetricValue, MetricSet, MetricValue}, - rrdd::{ - protocol_common::{DataSourceMetadata, DataSourceValue}, - protocol_v2::{indexmap::IndexMap, RrddMetadata}, - }, - utils::{ - delta::MetricSetModel, - mapping::{CustomMapping, DefaultMapping, MetadataMapping}, - }, -}; - -/// Adapter to convert protocol v3 metrics set into protocol v2 metadata and data. -#[derive(Clone)] -pub struct BridgeToV2 { - model: MetricSetModel, - latest_set: MetricSet, - custom_mappings: HashMap, CustomMapping>, - - metadata: RrddMetadata, - metadata_map: Vec<(Box, Box<[Label]>)>, -} - -/// Convert a MetricPoint into a protocol-v2 value. -fn metric_point_to_v2(metric_point: &MetricValue) -> DataSourceValue { - match metric_point.value { - MetricValue::Gauge(value) => DataSourceValue::from(value), - MetricValue::Counter { total, .. } => DataSourceValue::from(total), - _ => DataSourceValue::Undefined, - } -} - -impl BridgeToV2 { - pub fn new() -> Self { - Self { - model: MetricSetModel::default(), - latest_set: MetricSet::default(), - custom_mappings: HashMap::default(), - metadata: RrddMetadata { - datasources: IndexMap::default(), - }, - metadata_map: vec![], - } - } - - pub fn with_mappings(custom_mappings: HashMap, CustomMapping>) -> Self { - Self { - custom_mappings, - ..Default::default() - } - } - - fn metric_to_v2_metadata( - &self, - family_name: &str, - family: &MetricFamily, - metric: &Metric, - ) -> Option<(Box, DataSourceMetadata)> { - if let Some(custom_mapping) = self.custom_mappings.get(family_name) { - custom_mapping.convert(family_name, family, metric) - } else { - DefaultMapping.convert(family_name, family, metric) - } - } - - /// Update bridge information, returns true on metadata change. - pub fn update(&mut self, metrics_set: MetricSet) -> bool { - let delta = self.model.compute_delta(&metrics_set); - self.model.apply_delta(&delta); - - if !delta.added_families.is_empty() - || !delta.added_metrics.is_empty() - || !delta.removed_metrics.is_empty() - { - self.latest_set = metrics_set; - self.reset_metadata(); - true - } else { - self.latest_set = metrics_set; - false - } - } - - pub fn get_data(&self) -> Box<[DataSourceValue]> { - self.metadata_map - .iter() - .filter_map(|(family_name, labels)| self.get_first_metric_point(family_name, labels)) - .map(metric_point_to_v2) - .collect::>() - } - - pub fn get_metadata(&self) -> &RrddMetadata { - &self.metadata - } - - fn get_first_metric_point<'a>( - &'a self, - family_name: &str, - labels: &[Label], - ) -> Option<&'a MetricValue> { - self.latest_set - .families - .get(family_name) - .and_then(|family| { - family - .metrics - .iter() - // Filter by labels - .filter(|(_, metric)| metric.labels.as_ref() == labels) - // Only take first metrics_point - .find_map(|(_, metric)| metric.metrics_point.first()) - }) - } - - fn reset_metadata(&mut self) { - let (datasources, metadata_map) = self - .latest_set - .families - .iter() - // Combine family with family name and metrics. - .flat_map(|(name, family)| { - iter::zip(iter::repeat((name, family)), family.metrics.iter()) - }) - // Convert this data to protocol v2 metadata and mapping information. - .filter_map(|((family_name, family), (_, metric))| { - self.metric_to_v2_metadata(family_name, family, metric) - .map(|mapping| (mapping, (family_name.clone(), metric.labels.clone()))) - }) - .unzip(); - - self.metadata = RrddMetadata { datasources }; - self.metadata_map = metadata_map; - } -} - -impl Default for BridgeToV2 { - fn default() -> Self { - Self::new() - } -} diff --git a/plugins/xcp-metrics-plugin-common/src/lib.rs b/plugins/xcp-metrics-plugin-common/src/lib.rs deleted file mode 100644 index e0413a6..0000000 --- a/plugins/xcp-metrics-plugin-common/src/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod bridge; -pub mod plugin; -pub mod protocol_v2; -pub mod protocol_v3; - -//pub mod xenstore; \ No newline at end of file diff --git a/plugins/xcp-metrics-plugin-common/src/plugin.rs b/plugins/xcp-metrics-plugin-common/src/plugin.rs deleted file mode 100644 index b2ffd6e..0000000 --- a/plugins/xcp-metrics-plugin-common/src/plugin.rs +++ /dev/null @@ -1,143 +0,0 @@ -//! Utilities that manages communication with daemon using protocol v3 -//! under the hood and converting to protocol v2 if needed. -use std::{collections::HashMap, path::Path, time::Duration}; - -use tokio::time; - -use crate::{ - bridge::v3_to_v2::BridgeToV2, - protocol_v2::RrddPlugin, - protocol_v3::{utils::SimpleMetricSet, MetricsPlugin}, -}; -use xcp_metrics_common::utils::mapping::CustomMapping; - -pub const XCP_RRDD_PATH: &str = "/var/lib/xcp/xcp-rrdd"; - -/// Abstraction of a protocol v3 plugin. -pub trait XcpPlugin { - /// Update the state of the plugin. - fn update(&mut self) -> impl std::future::Future + Send; - - // Generate a new metric set representing the current state of data. - fn generate_metrics(&mut self) -> SimpleMetricSet; - - /// Get the plugin name (uid). - fn get_name(&self) -> &str; - - // Get plugin mappings - fn get_mappings(&self) -> Option, CustomMapping>>; -} - -fn arg0_starts_with_rrdp() -> bool { - let Some(arg0) = std::env::args().next() else { - return false; - }; - - Path::new(&arg0) - .file_name() - .unwrap_or_default() - .to_os_string() - .to_string_lossy() - .starts_with("rrdp-") -} - -/// Run the provided for either protocol v2 (converting from v3) or protocol v3 depending on `version`. -/// -/// Versions : -/// 2: Use a internal v3 to v2 bridge with `mappings` to convert from protocol v3 to protocol v2. -/// 3: Directly expose protocol v3 metrics to target daemon. -/// -/// If no target_daemon is provided, use default one. -pub async fn run_hybrid( - shared: impl XcpPlugin, - mut target_daemon_path: Option<&Path>, - mut version: Option, -) { - if target_daemon_path.is_none() && version.is_none() && arg0_starts_with_rrdp() { - tracing::info!("Program name starts with rrdp-*, use xcp-rrdd and protocol-v2 by default."); - target_daemon_path = Some(Path::new(&XCP_RRDD_PATH)); - version = Some(2); - } - - match version.unwrap_or(3) { - 2 => run_plugin_v2(shared, target_daemon_path).await, - 3 => run_plugin_v3(shared, target_daemon_path).await, - p => tracing::error!("Unknown protocol {p}"), - } -} - -pub async fn run_plugin_v2(mut shared: impl XcpPlugin, target_daemon_path: Option<&Path>) { - tracing::info!("Running protocol v2 plugin: {}", shared.get_name()); - let mut metrics = shared.generate_metrics(); - - let mut bridge = BridgeToV2::with_mappings(shared.get_mappings().unwrap_or_default()); - bridge.update(metrics.into()); - - let mut plugin = match RrddPlugin::new( - shared.get_name(), - bridge.get_metadata().clone(), - Some(&bridge.get_data()), - target_daemon_path, - ) - .await - { - Ok(plugin) => plugin, - Err(e) => { - tracing::error!("Unable to initialize plugin ({e})"); - return; - } - }; - - // Expose protocol v2 - loop { - tracing::debug!("Updating plugin state"); - - // Update sources - shared.update().await; - - // Fetch and push new metrics. - metrics = shared.generate_metrics(); - - if bridge.update(metrics.into()) { - if let Err(e) = plugin - .reset_metadata(bridge.get_metadata().clone(), Some(&bridge.get_data())) - .await - { - tracing::warn!("Unable to update metadata ({e}"); - } - } - - if let Err(e) = plugin.update_values(&bridge.get_data()).await { - tracing::warn!("Unable to update plugin values ({e})"); - } - - time::sleep(Duration::from_secs(1)).await; - } -} - -pub async fn run_plugin_v3(mut shared: impl XcpPlugin, target_daemon_path: Option<&Path>) { - tracing::info!("Running protocol v3 plugin: {}", shared.get_name()); - // Expose protocol v3 - // NOTE: some could be undefined values - let plugin = MetricsPlugin::new( - &shared.get_name().to_string(), - shared.generate_metrics().into(), - target_daemon_path, - ) - .await - .unwrap(); - - loop { - tracing::debug!("Updating plugin state"); - // Update sources - shared.update().await; - - // Fetch and push new metrics. - plugin - .update(shared.generate_metrics().into()) - .await - .unwrap(); - - time::sleep(Duration::from_secs(1)).await; - } -} diff --git a/plugins/xcp-metrics-plugin-common/src/protocol_v2.rs b/plugins/xcp-metrics-plugin-common/src/protocol_v2.rs deleted file mode 100644 index 4e6f1c5..0000000 --- a/plugins/xcp-metrics-plugin-common/src/protocol_v2.rs +++ /dev/null @@ -1,173 +0,0 @@ -use std::path::{Path, PathBuf}; - -use tokio::{ - fs::{create_dir_all, OpenOptions}, - io::AsyncWriteExt, -}; - -use xapi::{ - rpc::{ - message::{parse_http_response, RpcKind}, - methods::rrdd::{PluginLocalDeregister, PluginLocalRegister}, - }, - unix::METRICS_SHM_PATH, -}; -use xcp_metrics_common::rrdd::{ - protocol_common::DataSourceValue, - protocol_v2::{values_to_raw, RrddMessageHeader, RrddMetadata}, -}; - -pub struct RrddPlugin { - uid: Box, - header: RrddMessageHeader, - metrics_path: PathBuf, - target_daemon_path: PathBuf, -} - -const DEFAULT_DAEMON: &str = "/var/lib/xcp/xcp-metrics"; - -impl RrddPlugin { - /// Create and register a new plugin. - pub async fn new( - uid: &'_ str, - metadata: RrddMetadata, - initial_values: Option<&[DataSourceValue]>, - target_daemon_path: Option<&Path>, - ) -> anyhow::Result { - let (header, metadata_str) = Self::generate_initial_header(metadata, initial_values); - - let plugin = Self { - uid: uid.into(), - header, - metrics_path: Path::new(METRICS_SHM_PATH).join(uid), - target_daemon_path: target_daemon_path - .unwrap_or(Path::new(DEFAULT_DAEMON)) - .to_path_buf(), - }; - - plugin.reset_file(Some(&metadata_str)).await?; - plugin.advertise_plugin().await?; - - Ok(plugin) - } - - /// Push new values to the shared file. - /// - /// # Condition - /// The length of `new_values` must match the latest sent metadata (either by [Self::new] or [Self::reset_metadata]). - pub async fn update_values(&mut self, new_values: &[DataSourceValue]) -> anyhow::Result<()> { - self.header.update_values(&values_to_raw(new_values))?; - self.reset_file(None).await - } - - /// Advertise the existence of the plugin to the main daemon. - pub async fn advertise_plugin(&self) -> anyhow::Result<()> { - let request = PluginLocalRegister { - info: "Five_Seconds".into(), - protocol: "V2".into(), - uid: self.uid.to_string(), - }; - - let response = xapi::unix::send_rpc_to( - &self.target_daemon_path, - "POST", - &request, - &self.uid, /* use uid as user-agent */ - RpcKind::XmlRpc, - ) - .await - .map_err(|e| { - anyhow::anyhow!( - "Can't reach '{}' daemon ({e})", - self.target_daemon_path.to_string_lossy() - ) - })?; - - tracing::info!("RPC Response: {:?}", parse_http_response(response).await); - - Ok(()) - } - - /// Replace the metadata of the shared file. - /// - /// # Condition - /// The length of `initial_values` must match the `metadata`. - pub async fn reset_metadata( - &mut self, - metadata: RrddMetadata, - initial_values: Option<&[DataSourceValue]>, - ) -> anyhow::Result<()> { - let (header, metadata_str) = - Self::generate_initial_header(metadata.clone(), initial_values); - - self.header = header; - self.reset_file(Some(&metadata_str)).await - } - - async fn reset_file(&self, raw_metadata: Option<&str>) -> anyhow::Result<()> { - // Create directory if doesn't exist. - create_dir_all(METRICS_SHM_PATH).await?; - - let mut options = OpenOptions::new(); - options.create(true); - options.truncate(false); - options.write(true); - - let mut file = options.open(&self.metrics_path).await?; - - let mut header_buffer = vec![]; - self.header.write(&mut header_buffer)?; - file.write_all(&header_buffer).await?; - - if let Some(raw_metadata) = raw_metadata { - file.write_all(raw_metadata.as_bytes()).await?; - } - - Ok(()) - } - - fn generate_initial_header( - metadata: RrddMetadata, - initial_values: Option<&[DataSourceValue]>, - ) -> (RrddMessageHeader, Box) { - let raw_values = if let Some(init) = initial_values { - values_to_raw(init) - } else { - vec![[0; 8]; metadata.datasources.len()].into_boxed_slice() - }; - - RrddMessageHeader::generate(&raw_values, metadata) - } - - /// Deregister the plugin from the daemon. - pub async fn deregister_plugin(self) { - tracing::info!("Deregistering {}...", &self.uid); - - // Unregister plugin - let request = PluginLocalDeregister { - uid: self.uid.to_string(), - }; - - match xapi::unix::send_rpc_to( - &self.target_daemon_path, - "POST", - &request, - &self.uid, /* use uid as user-agent */ - RpcKind::XmlRpc, - ) - .await - { - Ok(response) => { - tracing::info!("RPC Response: {:?}", parse_http_response(response).await) - } - Err(e) => { - tracing::error!("Unable to unregister plugin ({e})") - } - } - - // Delete plugin file. - if let Err(e) = tokio::fs::remove_file(self.metrics_path).await { - tracing::warn!("Unable to remove plugin file: {e}") - } - } -} diff --git a/plugins/xcp-metrics-plugin-common/src/protocol_v3/mod.rs b/plugins/xcp-metrics-plugin-common/src/protocol_v3/mod.rs deleted file mode 100644 index 11806e7..0000000 --- a/plugins/xcp-metrics-plugin-common/src/protocol_v3/mod.rs +++ /dev/null @@ -1,119 +0,0 @@ -//! xcp-metrics plugin protocol v3 framework. -pub mod utils; - -use std::path::{Path, PathBuf}; - -use tokio::fs::{create_dir_all, OpenOptions}; - -use xapi::{ - rpc::{ - message::{parse_http_response, RpcKind}, - methods::rrdd::{PluginMetricsDeregister, PluginMetricsRegister}, - }, - unix::METRICS_SHM_PATH, -}; -use xcp_metrics_common::{metrics::MetricSet, protocol_v3}; - -pub struct MetricsPlugin { - uid: Box, - metrics_path: PathBuf, - target_daemon_path: PathBuf, -} - -const DEFAULT_DAEMON: &str = "/var/lib/xcp/xcp-metrics"; - -impl MetricsPlugin { - /// Create and register a new plugin. - pub async fn new( - uid: &'_ str, - metrics: MetricSet, - target_daemon_path: Option<&Path>, - ) -> anyhow::Result { - let plugin = Self { - uid: uid.into(), - metrics_path: Path::new(METRICS_SHM_PATH).join(uid), - target_daemon_path: target_daemon_path - .unwrap_or(Path::new(DEFAULT_DAEMON)) - .to_path_buf(), - }; - - plugin.update(metrics).await?; - plugin.advertise_plugin().await?; - - Ok(plugin) - } - - pub async fn update(&self, metrics: MetricSet) -> anyhow::Result<()> { - create_dir_all(METRICS_SHM_PATH).await?; - - let mut options = OpenOptions::new(); - options.create(true); - options.truncate(false); - options.write(true); - - let mut file = options.open(&self.metrics_path).await?; - - protocol_v3::generate_v3_async(&mut file, None, metrics).await?; - - Ok(()) - } - - /// Advertise the existence of the plugin to the main daemon. - pub async fn advertise_plugin(&self) -> anyhow::Result<()> { - let request = PluginMetricsRegister { - version: "OpenMetrics 1.0.0".into(), - uid: self.uid.to_string(), - }; - - let response = xapi::unix::send_rpc_to( - &self.target_daemon_path, - "POST", - &request, - &self.uid, /* use uid as user-agent */ - RpcKind::JsonRpc, - ) - .await - .map_err(|e| { - anyhow::anyhow!( - "Can't reach '{}' daemon ({e})", - self.target_daemon_path.to_string_lossy() - ) - })?; - - tracing::debug!("RPC Response: {:?}", parse_http_response(response).await); - - Ok(()) - } - - /// Deregister the plugin from the daemon. - pub async fn deregister_plugin(self) { - tracing::info!("Deregistering {}...", &self.uid); - - // Unregister plugin - let request = PluginMetricsDeregister { - uid: self.uid.to_string(), - }; - - match xapi::unix::send_rpc_to( - &self.target_daemon_path, - "POST", - &request, - &self.uid, /* use uid as user-agent */ - RpcKind::JsonRpc, - ) - .await - { - Ok(response) => { - tracing::debug!("RPC Response: {:?}", parse_http_response(response).await) - } - Err(e) => { - tracing::error!("Unable to unregister plugin ({e})") - } - } - - // Delete plugin file. - if let Err(e) = tokio::fs::remove_file(self.metrics_path).await { - tracing::warn!("Unable to remove plugin file: {e}"); - } - } -} diff --git a/plugins/xcp-metrics-plugin-common/src/protocol_v3/utils.rs b/plugins/xcp-metrics-plugin-common/src/protocol_v3/utils.rs deleted file mode 100644 index 0efa674..0000000 --- a/plugins/xcp-metrics-plugin-common/src/protocol_v3/utils.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! Simpler metrics representation for plugins. - -use std::{collections::HashMap, time::SystemTime}; - -use xcp_metrics_common::metrics::{ - Label, Metric, MetricFamily, MetricSet, MetricType, MetricValue, MetricValue, -}; - -#[derive(Clone, Debug)] -pub struct SimpleMetricSet { - pub families: HashMap, -} - -impl From for MetricSet { - fn from(SimpleMetricSet { families }: SimpleMetricSet) -> Self { - Self { - families: families - .into_iter() - .map(|(name, family)| (name.into_boxed_str(), family.into())) - .collect(), - } - } -} - -#[derive(Clone, Debug)] -pub struct SimpleMetricFamily { - pub metric_type: MetricType, - pub unit: Box, - pub help: Box, - - pub metrics: Vec, -} - -impl From for MetricFamily { - fn from( - SimpleMetricFamily { - metric_type, - unit, - help, - metrics, - }: SimpleMetricFamily, - ) -> Self { - Self { - reference_count: 1, - metric_type, - unit, - help, - metrics: metrics - .into_iter() - .map(|simple_metric| (uuid::Uuid::new_v4(), Metric::from(simple_metric))) - .collect(), - } - } -} - -#[derive(Clone, Debug)] -pub struct SimpleMetric { - pub labels: Vec