+ source_id
test-org/prometheus-exporter/pipeline/pr-rc This commit looks good Details

pull/18/head
prplV 2025-05-19 08:05:51 -04:00
parent 2ccf1840c0
commit c34a0fd176
3 changed files with 12 additions and 58 deletions

View File

@ -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;
}
},

View File

@ -45,15 +45,13 @@ impl MetricsProcesser {
metric: &MetricOutput,
metric_name: &str,
metric_desc: &str,
// status: Option<isize>,
// device: Option<isize>,
) -> Option<Box<dyn Collector>> {
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));
}

View File

@ -19,13 +19,14 @@ pub mod v3 {
pub desc : Option<Cow<'a, String>>,
pub status: Option<isize>,
pub device: Option<isize>,
pub module: Option<isize>,
#[serde(rename = "source")]
pub source_id: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct PrometheusMetrics<'a> {
pub service_name: String,
pub endpoint_name: String,
// pub endpoint_name: String,
pub metrics: Vec<MetricOutput<'a>>,
}
}