new struct (temp)

feature/1117
prplV 2025-03-04 14:58:46 +03:00
parent 2ca105e67f
commit 4b730be85b
1 changed files with 65 additions and 3 deletions

View File

@ -243,7 +243,7 @@ pub mod v3 {
pub value : Value, pub value : Value,
} }
impl MetricOutput { 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 { MetricOutput {
id : id.to_string(), id : id.to_string(),
json_type : json_type.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)] #[derive(Serialize, Deserialize, Debug)]
pub struct PrometheusMetrics { pub struct PrometheusMetrics {
@ -281,10 +302,33 @@ pub mod v3 {
str_metrics.len() str_metrics.len()
} }
} }
#[derive(Serialize, Deserialize, Debug)]
pub struct PrometheusMetricsExtended {
pub service_name: String,
pub endpoint_name: String,
pub metrics: Vec<MetricOutputExtended>,
}
impl PrometheusMetricsExtended {
pub async fn new_zvks(metrics: Vec<MetricOutputExtended>) -> 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 { pub mod enode_monitoring {
use std::hash::Hash;
use super::*; use super::*;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -383,7 +427,14 @@ pub mod enode_monitoring {
fn display(&self) -> String; fn display(&self) -> String;
} }
impl<T> GenericUrl for [T] pub trait LazyUnzip<K, V>
where
V : Clone,
K : Hash + Eq + Clone {
fn lazy_unzip(&self) -> HashMap<K, V>;
}
impl<T> GenericUrl for [(T, T)]
where T : Display { where T : Display {
fn display(&self) -> String { fn display(&self) -> String {
let mut vec: Vec<String> = Vec::new(); let mut vec: Vec<String> = Vec::new();
@ -394,12 +445,23 @@ pub mod enode_monitoring {
if id > 0 { if id > 0 {
vec.push(",".to_owned()); vec.push(",".to_owned());
} }
vec.push(format!("%22{}%22", val)); vec.push(format!("%22{}%22", val.0));
}); });
vec.push("%5D".to_owned()); vec.push("%5D".to_owned());
vec.concat() vec.concat()
} }
} }
impl<K, V> LazyUnzip<K, V> for [(K, V)]
where
V : Clone,
K : Hash + Eq + Clone {
fn lazy_unzip(&self) -> HashMap<K, V> {
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 { pub fn get_chunk_size(total_measures: usize) -> usize {
match total_measures { match total_measures {