final fixes

feature/160
prplV 2025-05-20 04:37:09 -04:00
parent 3cca316978
commit 774a517def
4 changed files with 60 additions and 34 deletions

View File

@ -183,7 +183,7 @@ impl Requester {
error!("Error casting jitter value from participant {} (id: {}), conference - {} (id: {}). Error: {}", name, id, conf_name, conf_id, er);
Value::Null
});
metrics.add(MetricOutputExtended::new_with_slices(&metric_id, "int", "Vinteo native", &desc, None, None,val));
metrics.add(MetricOutputExtended::new_with_slices(&metric_id, &metric_id,"int", "Vinteo native", &desc, None, None,val));
});
});
metrics

View File

@ -333,26 +333,23 @@ impl MonitoringImporter {
None => "undefined-device".to_string(),
}
};
let device_id = device_id.trim_end_matches('"');
if let Some(links) = device.get("links") {
if let Some(measures) = links.as_array() {
for measure in measures.iter() {
let dola_id = measure.get("$id");
let dola_id = measure.get("id");
let id = measure.get("measure_id");
let source = measure.get("source_id");
let desc = measure.get("name");
dbg!(&dola_id);
dbg!(&id);
dbg!(&source);
dbg!(&desc);
if id.is_some() && source.is_some() && dola_id.is_some() {
let dola_id = dola_id.unwrap().as_str().unwrap_or_else(|| "no-id");
let dola_id = format!("measure${}", dola_id.unwrap().as_i64().unwrap_or_else(|| 0));
let id = id.unwrap().as_str().unwrap_or_else(|| "no-name");
let source = source.unwrap().as_str().unwrap_or_else(|| "no-source");
let desc = desc.unwrap_or_else(|| &Value::Null).as_str().unwrap_or_else(|| "no description");
if source.is_empty() {
return Err(Error::msg("Invalid JSON in response. Wrong types of fields (`measure_id` or `source_id`)"));
}
vec.push(MetricInstance::new(dola_id, id, desc, device_id.as_ref(), source));
vec.push(MetricInstance::new(&dola_id, id, desc, device_id.as_ref(), source));
}
}
}
@ -510,37 +507,65 @@ impl MonitoringImporter {
if id.is_none() || val.is_none() {
return Err(Error::msg("Cannot get values of fields `id` and `value` from JSON Response"))
}
let id = id.unwrap().as_str().unwrap_or_else(|| "").replace("$", "_");
let id = id.unwrap().as_str().unwrap_or_else(|| "");
let default_meta = MetricMeta::default();
let meta = hm.get(id).unwrap_or_else(|| &default_meta);
let id = id.replace("$", "_");
let val = val.unwrap();
let device = meta.device.parse::<usize>().unwrap_or_else(|_| 0);
if id.is_empty() {
return Err(Error::msg("Empty `id` field. Invalid JSON response"))
}
let default_meta = MetricMeta::default();
let meta = hm.get(&id).unwrap_or_else(|| &default_meta);
let device = meta.device.parse::<usize>().unwrap_or_else(|_| 0);
Ok(MetricOutputExtended {
id : id.to_owned(),
json_type : match val {
let temp = MetricOutputExtended::new_with_slices(
id.as_ref(),
&meta.name,
{
match val {
Value::Number(val) => {
if val.is_i64() {
"i64".to_owned()
"i64"
} else if val.is_u64() {
"u64".to_owned()
"u64"
} else {
"f64".to_owned()
"f64"
}
},
_ => "unknown".to_owned(),
_ => "unknown",
}
},
addr : "enode.monitoring.api".to_owned(),
desc : meta.desc.clone(),
value : val.clone(),
device: Some(device),
source: Some(meta.source.clone()),
status: 0,
})
"enode.monitoring.api",
&meta.desc,
Some(device),
Some(meta.source.clone()),
val.clone(),
);
dbg!(temp);
todo!();
Ok(temp)
// Ok(MetricOutputExtended {
// id : id.to_owned(),
// name : &meta.name,
// json_type : match val {
// Value::Number(val) => {
// if val.is_i64() {
// "i64".to_owned()
// } else if val.is_u64() {
// "u64".to_owned()
// } else {
// "f64".to_owned()
// }
// },
// _ => "unknown".to_owned(),
// },
// addr : "enode.monitoring.api".to_owned(),
// desc : meta.desc.clone(),
// value : val.clone(),
// device: Some(device),
// source: Some(meta.source.clone()),
// status: 0,
// })
}
}

View File

@ -97,9 +97,8 @@ impl<'a> ApiPoll<'a> {
error!("Bad JSON in response. Error: {}", er);
},
Ok(_) => {
let endpoint_name = &metrics.name;
let preproc = JsonParser::parse(&metrics.measure, &response);
let preproc = PrometheusMetrics::new(&service_id, endpoint_name, preproc);
let preproc = PrometheusMetrics::new(&service_id, preproc);
match Exporter::export_metrics(preproc).await {
Ok(bytes) => {
info!("Successfully exported {} bytes of metrics data to Prometheus", bytes);

View File

@ -265,6 +265,7 @@ pub mod v3 {
#[derive(Serialize, Deserialize, Debug)]
pub struct MetricOutputExtended {
pub id : String,
pub name : String,
#[serde(rename = "type")]
pub json_type : String,
pub addr : String,
@ -276,9 +277,10 @@ pub mod v3 {
pub source: Option<String>,
}
impl MetricOutputExtended {
pub fn new_with_slices(id : &str, json_type : &str, addr: &str, desc : &str, device: Option<usize>, source: Option<String>, value : Value) -> Self {
pub fn new_with_slices(id : &str, name: &str, json_type : &str, addr: &str, desc : &str, device: Option<usize>, source: Option<String>, value : Value) -> Self {
MetricOutputExtended {
id : id.to_string(),
name : name.to_string(),
json_type : json_type.to_string(),
addr : addr.to_string(),
value : value,
@ -293,21 +295,21 @@ pub mod v3 {
#[derive(Serialize, Deserialize, Debug)]
pub struct PrometheusMetrics {
pub service_name: String,
pub endpoint_name: String,
// pub endpoint_name: String,
pub metrics: Vec<MetricOutput>,
}
impl PrometheusMetrics {
pub fn new(service: &str, endpoint: &str, metrics: Vec<MetricOutput>) -> Self {
pub fn new(service: &str, metrics: Vec<MetricOutput>) -> Self {
Self {
service_name: service.to_string(),
endpoint_name: endpoint.to_string(),
// endpoint_name: endpoint.to_string(),
metrics: metrics
}
}
pub async fn new_zvks(metrics: Vec<MetricOutput>) -> Self {
Self {
service_name : "zvks".to_owned(),
endpoint_name : "apiforsnmp".to_owned(),
// endpoint_name : "apiforsnmp".to_owned(),
metrics : metrics,
}
}