From 4b730be85bab68dc6960d066145f90cf1c6e5140 Mon Sep 17 00:00:00 2001 From: prplV Date: Tue, 4 Mar 2025 14:58:46 +0300 Subject: [PATCH] new struct (temp) --- crates/integr-structs/src/api.rs | 68 ++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/crates/integr-structs/src/api.rs b/crates/integr-structs/src/api.rs index 0c646f8..d96feeb 100644 --- a/crates/integr-structs/src/api.rs +++ b/crates/integr-structs/src/api.rs @@ -243,7 +243,7 @@ pub mod v3 { pub value : Value, } impl MetricOutput { - pub fn new_with_slices(id : &str, json_type : &str, addr: &str,value : Value) -> Self { + pub fn new_with_slices(id : &str, json_type : &str, addr: &str, value : Value) -> Self { MetricOutput { id : id.to_string(), json_type : json_type.to_string(), @@ -252,6 +252,27 @@ pub mod v3 { } } } + #[derive(Serialize, Deserialize, Debug)] + pub struct MetricOutputExtended { + pub id : String, + #[serde(rename = "type")] + pub json_type : String, + pub addr : String, + pub value : Value, + #[serde(rename = "description")] + pub desc : String, + } + impl MetricOutputExtended { + pub fn new_with_slices(id : &str, json_type : &str, addr: &str, desc : &str, value : Value) -> Self { + MetricOutputExtended { + id : id.to_string(), + json_type : json_type.to_string(), + addr : addr.to_string(), + value : value, + desc : desc.to_string(), + } + } + } #[derive(Serialize, Deserialize, Debug)] pub struct PrometheusMetrics { @@ -281,10 +302,33 @@ pub mod v3 { str_metrics.len() } } + #[derive(Serialize, Deserialize, Debug)] + pub struct PrometheusMetricsExtended { + pub service_name: String, + pub endpoint_name: String, + pub metrics: Vec, + } + impl PrometheusMetricsExtended { + pub async fn new_zvks(metrics: Vec) -> Self { + Self { + service_name : "zvks".to_owned(), + endpoint_name : "apiforsnmp".to_owned(), + metrics : metrics, + } + } + pub fn get_bytes_len(&self) -> usize { + let str_metrics = serde_json::to_vec(self).unwrap_or_else( + |_| Vec::new() + ); + str_metrics.len() + } + } } pub mod enode_monitoring { + use std::hash::Hash; + use super::*; #[derive(Debug, Serialize)] @@ -383,7 +427,14 @@ pub mod enode_monitoring { fn display(&self) -> String; } - impl GenericUrl for [T] + pub trait LazyUnzip + where + V : Clone, + K : Hash + Eq + Clone { + fn lazy_unzip(&self) -> HashMap; + } + + impl GenericUrl for [(T, T)] where T : Display { fn display(&self) -> String { let mut vec: Vec = Vec::new(); @@ -394,12 +445,23 @@ pub mod enode_monitoring { if id > 0 { vec.push(",".to_owned()); } - vec.push(format!("%22{}%22", val)); + vec.push(format!("%22{}%22", val.0)); }); vec.push("%5D".to_owned()); vec.concat() } } + impl LazyUnzip for [(K, V)] + where + V : Clone, + K : Hash + Eq + Clone { + fn lazy_unzip(&self) -> HashMap { + let mut hm = HashMap::new(); + self.into_iter() + .for_each(|(key, val)| {hm.insert(key.to_owned(), val.to_owned());}); + hm + } + } pub fn get_chunk_size(total_measures: usize) -> usize { match total_measures {