diff --git a/src/endpoints.rs b/src/endpoints.rs index d167353..eb45056 100644 --- a/src/endpoints.rs +++ b/src/endpoints.rs @@ -82,13 +82,6 @@ pub async fn update_metrics( ) -> impl IntoResponse { trace!("post on /update"); let service = &request.service_name; - // let endpoint = &request.endpoint_name; - // if request.with_device_status_and_module() { - - // } else { - - // } - let mut metrics = Vec::new(); for i in request.metrics { @@ -253,44 +246,6 @@ pub fn update_or_insert_metric<'a>( }, } } - - // match registry.register(prod.get_collector()) { - // Ok(_) => { - // info!("Metric `{}` was registered!", metric_name); - // }, - // Err(er) => { - // // update or throw away - // match er { - // Error::AlreadyReg => { - // trace!("processing already regged metric"); - // match registry.unregister(prod.get_collector()) { - // Ok(_) => { - // if let Err(er) = registry.register(prod.get_collector()) { - // warn!("Cannot update metric `{}`", metric_name); - // return Err(anyhow::Error::msg( - // format!("Cannot update metric `{}` due to {}", metric_name, er) - // )) - // } else { - // info!("OK on metric `{}` update", metric_name); - // } - // }, - // Err(er) => { - // error!("Cannot unregister metric `{}` due to {}", metric_name, er); - // return Err(anyhow::Error::msg( - // format!("Cannot unregister metric `{}` due to {}", metric_name, er) - // )) - // }, - // } - // }, - // _ => { - // error!("Cannot register new metric `{}` due to {}", metric_name, er); - // return Err(anyhow::Error::msg( - // format!("Cannot register new metric `{}` due to {}", metric_name, er) - // )) - // } - // } - // }, - // } Ok(()) } @@ -324,16 +279,16 @@ impl CompareGaugeVec for GaugeVec { match (lables.get("status"), new_lables.get("status")) { (Some(&status), Some(_)) => { match ( - (lables.get("device"), lables.get("module")), - (new_lables.get("device"), new_lables.get("module")), + (lables.get("device"), lables.get("source_id")), + (new_lables.get("device"), new_lables.get("source_id")), ) { - ((Some(&device), Some(&module)), - (Some(&new_device), Some(&new_module))) => { + ((Some(&device), Some(&source_id)), + (Some(&new_device), Some(&new_source_id))) => { /* */ dbg!(1); - if device != new_device || module != new_module { + if device != new_device || source_id != new_source_id { dbg!(2); - self.with_label_values(&[device, module, status]).set(value); + self.with_label_values(&[device, source_id, status]).set(value); // continue 'outer; } }, diff --git a/src/metrics.rs b/src/metrics.rs index b47270d..40e0a10 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -45,15 +45,13 @@ impl MetricsProcesser { metric: &MetricOutput, metric_name: &str, metric_desc: &str, - // status: Option, - // device: Option, ) -> Option> { trace!("fn gauge_from_number is running"); if let Some(status) = metric.status { if let Some(device) = metric.device { - if let Some(module) = metric.module { - let vec = GaugeVec::new(opts!(metric_name, metric_desc), &["status", "device", "module"]).unwrap(); - vec.with_label_values(&[&status.to_string(), &device.to_string(), &module.to_string()]).set(metric.value.as_f64().unwrap_or_else(|| 0.0)); + if let Some(source_id) = &metric.source_id { + let vec = GaugeVec::new(opts!(metric_name, metric_desc), &["status", "device", "source_id"]).unwrap(); + vec.with_label_values(&[&status.to_string(), &device.to_string(), &source_id.to_string()]).set(metric.value.as_f64().unwrap_or_else(|| 0.0)); debug!("processed metric: {:?}", &vec); return Some(Box::new(vec)); } diff --git a/src/structs.rs b/src/structs.rs index 8095768..86b60e9 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -19,13 +19,14 @@ pub mod v3 { pub desc : Option>, pub status: Option, pub device: Option, - pub module: Option, + #[serde(rename = "source")] + pub source_id: Option, } #[derive(Serialize, Deserialize, Debug)] pub struct PrometheusMetrics<'a> { pub service_name: String, - pub endpoint_name: String, + // pub endpoint_name: String, pub metrics: Vec>, } } \ No newline at end of file