final fixes
parent
3cca316978
commit
774a517def
|
|
@ -183,7 +183,7 @@ impl Requester {
|
||||||
error!("Error casting jitter value from participant {} (id: {}), conference - {} (id: {}). Error: {}", name, id, conf_name, conf_id, er);
|
error!("Error casting jitter value from participant {} (id: {}), conference - {} (id: {}). Error: {}", name, id, conf_name, conf_id, er);
|
||||||
Value::Null
|
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
|
metrics
|
||||||
|
|
|
||||||
|
|
@ -333,26 +333,23 @@ impl MonitoringImporter {
|
||||||
None => "undefined-device".to_string(),
|
None => "undefined-device".to_string(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let device_id = device_id.trim_end_matches('"');
|
||||||
if let Some(links) = device.get("links") {
|
if let Some(links) = device.get("links") {
|
||||||
if let Some(measures) = links.as_array() {
|
if let Some(measures) = links.as_array() {
|
||||||
for measure in measures.iter() {
|
for measure in measures.iter() {
|
||||||
let dola_id = measure.get("$id");
|
let dola_id = measure.get("id");
|
||||||
let id = measure.get("measure_id");
|
let id = measure.get("measure_id");
|
||||||
let source = measure.get("source_id");
|
let source = measure.get("source_id");
|
||||||
let desc = measure.get("name");
|
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() {
|
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 id = id.unwrap().as_str().unwrap_or_else(|| "no-name");
|
||||||
let source = source.unwrap().as_str().unwrap_or_else(|| "no-source");
|
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");
|
let desc = desc.unwrap_or_else(|| &Value::Null).as_str().unwrap_or_else(|| "no description");
|
||||||
if source.is_empty() {
|
if source.is_empty() {
|
||||||
return Err(Error::msg("Invalid JSON in response. Wrong types of fields (`measure_id` or `source_id`)"));
|
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() {
|
if id.is_none() || val.is_none() {
|
||||||
return Err(Error::msg("Cannot get values of fields `id` and `value` from JSON Response"))
|
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 val = val.unwrap();
|
||||||
|
let device = meta.device.parse::<usize>().unwrap_or_else(|_| 0);
|
||||||
|
|
||||||
if id.is_empty() {
|
if id.is_empty() {
|
||||||
return Err(Error::msg("Empty `id` field. Invalid JSON response"))
|
return Err(Error::msg("Empty `id` field. Invalid JSON response"))
|
||||||
}
|
}
|
||||||
let default_meta = MetricMeta::default();
|
let temp = MetricOutputExtended::new_with_slices(
|
||||||
let meta = hm.get(&id).unwrap_or_else(|| &default_meta);
|
id.as_ref(),
|
||||||
let device = meta.device.parse::<usize>().unwrap_or_else(|_| 0);
|
&meta.name,
|
||||||
|
{
|
||||||
Ok(MetricOutputExtended {
|
match val {
|
||||||
id : id.to_owned(),
|
|
||||||
json_type : match val {
|
|
||||||
Value::Number(val) => {
|
Value::Number(val) => {
|
||||||
if val.is_i64() {
|
if val.is_i64() {
|
||||||
"i64".to_owned()
|
"i64"
|
||||||
} else if val.is_u64() {
|
} else if val.is_u64() {
|
||||||
"u64".to_owned()
|
"u64"
|
||||||
} else {
|
} else {
|
||||||
"f64".to_owned()
|
"f64"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => "unknown".to_owned(),
|
_ => "unknown",
|
||||||
|
}
|
||||||
},
|
},
|
||||||
addr : "enode.monitoring.api".to_owned(),
|
"enode.monitoring.api",
|
||||||
desc : meta.desc.clone(),
|
&meta.desc,
|
||||||
value : val.clone(),
|
Some(device),
|
||||||
device: Some(device),
|
Some(meta.source.clone()),
|
||||||
source: Some(meta.source.clone()),
|
val.clone(),
|
||||||
status: 0,
|
);
|
||||||
})
|
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,
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,8 @@ impl<'a> ApiPoll<'a> {
|
||||||
error!("Bad JSON in response. Error: {}", er);
|
error!("Bad JSON in response. Error: {}", er);
|
||||||
},
|
},
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let endpoint_name = &metrics.name;
|
|
||||||
let preproc = JsonParser::parse(&metrics.measure, &response);
|
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 {
|
match Exporter::export_metrics(preproc).await {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
info!("Successfully exported {} bytes of metrics data to Prometheus", bytes);
|
info!("Successfully exported {} bytes of metrics data to Prometheus", bytes);
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,7 @@ pub mod v3 {
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct MetricOutputExtended {
|
pub struct MetricOutputExtended {
|
||||||
pub id : String,
|
pub id : String,
|
||||||
|
pub name : String,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub json_type : String,
|
pub json_type : String,
|
||||||
pub addr : String,
|
pub addr : String,
|
||||||
|
|
@ -276,9 +277,10 @@ pub mod v3 {
|
||||||
pub source: Option<String>,
|
pub source: Option<String>,
|
||||||
}
|
}
|
||||||
impl MetricOutputExtended {
|
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 {
|
MetricOutputExtended {
|
||||||
id : id.to_string(),
|
id : id.to_string(),
|
||||||
|
name : name.to_string(),
|
||||||
json_type : json_type.to_string(),
|
json_type : json_type.to_string(),
|
||||||
addr : addr.to_string(),
|
addr : addr.to_string(),
|
||||||
value : value,
|
value : value,
|
||||||
|
|
@ -293,21 +295,21 @@ pub mod v3 {
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct PrometheusMetrics {
|
pub struct PrometheusMetrics {
|
||||||
pub service_name: String,
|
pub service_name: String,
|
||||||
pub endpoint_name: String,
|
// pub endpoint_name: String,
|
||||||
pub metrics: Vec<MetricOutput>,
|
pub metrics: Vec<MetricOutput>,
|
||||||
}
|
}
|
||||||
impl PrometheusMetrics {
|
impl PrometheusMetrics {
|
||||||
pub fn new(service: &str, endpoint: &str, metrics: Vec<MetricOutput>) -> Self {
|
pub fn new(service: &str, metrics: Vec<MetricOutput>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
service_name: service.to_string(),
|
service_name: service.to_string(),
|
||||||
endpoint_name: endpoint.to_string(),
|
// endpoint_name: endpoint.to_string(),
|
||||||
metrics: metrics
|
metrics: metrics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub async fn new_zvks(metrics: Vec<MetricOutput>) -> Self {
|
pub async fn new_zvks(metrics: Vec<MetricOutput>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
service_name : "zvks".to_owned(),
|
service_name : "zvks".to_owned(),
|
||||||
endpoint_name : "apiforsnmp".to_owned(),
|
// endpoint_name : "apiforsnmp".to_owned(),
|
||||||
metrics : metrics,
|
metrics : metrics,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue