fail if no metric is found for a series
This commit is contained in:
parent
71c87271e1
commit
d22e5659fc
|
|
@ -0,0 +1,22 @@
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use protocol::ProtocolError;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
|
pub enum WaybarCollectdError {
|
||||||
|
ProtocolError(ProtocolError),
|
||||||
|
NoMatchingMetricFound(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for WaybarCollectdError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let message = match self {
|
||||||
|
Self::ProtocolError(val) => format!("Collectd integration failed: {val}"),
|
||||||
|
Self::NoMatchingMetricFound(name) => {
|
||||||
|
format!("No matching metric found for {}", name)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
f.write_str(&message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
mod config;
|
mod config;
|
||||||
|
mod err;
|
||||||
mod observables;
|
mod observables;
|
||||||
mod runner;
|
mod runner;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use protocol::{Protocol, ProtocolError};
|
use protocol::{Protocol, ProtocolError};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::config::MetricSpecification;
|
use crate::{config::MetricSpecification, err::WaybarCollectdError};
|
||||||
|
|
||||||
pub struct Observable {
|
pub struct Observable {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
@ -23,8 +23,10 @@ impl Observable {
|
||||||
proto: &mut Protocol,
|
proto: &mut Protocol,
|
||||||
name: &str,
|
name: &str,
|
||||||
includes: &Vec<MetricSpecification>,
|
includes: &Vec<MetricSpecification>,
|
||||||
) -> Result<Observable, ProtocolError> {
|
) -> Result<Observable, WaybarCollectdError> {
|
||||||
let all_values = proto.list()?;
|
let all_values = proto
|
||||||
|
.list()
|
||||||
|
.map_err(|e| WaybarCollectdError::ProtocolError(e))?;
|
||||||
let regexes: Vec<MetricRegex> = includes
|
let regexes: Vec<MetricRegex> = includes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| MetricRegex {
|
.map(|i| MetricRegex {
|
||||||
|
|
@ -32,7 +34,7 @@ impl Observable {
|
||||||
value: i.value.to_string(),
|
value: i.value.to_string(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let filtered_values = all_values
|
let filtered_values: Vec<Metric> = all_values
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|v| {
|
.filter_map(|v| {
|
||||||
for r in regexes.iter() {
|
for r in regexes.iter() {
|
||||||
|
|
@ -48,10 +50,14 @@ impl Observable {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(Observable {
|
if filtered_values.len() == 0 {
|
||||||
name: name.to_string(),
|
Err(WaybarCollectdError::NoMatchingMetricFound(name.to_string()))
|
||||||
metrics: filtered_values,
|
} else {
|
||||||
})
|
Ok(Observable {
|
||||||
|
name: name.to_string(),
|
||||||
|
metrics: filtered_values,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sample(&self, proto: &mut Protocol) -> Result<f32, ProtocolError> {
|
pub fn sample(&self, proto: &mut Protocol) -> Result<f32, ProtocolError> {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use draw::{StackedConfig, StackedSeries, StackedSeriesConfig, stacked};
|
use draw::{StackedConfig, StackedSeries, StackedSeriesConfig, stacked};
|
||||||
use protocol::{Protocol, ProtocolError};
|
use protocol::Protocol;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::GraphConfig,
|
config::GraphConfig,
|
||||||
|
err::WaybarCollectdError,
|
||||||
observables::{Observable, ObservableCollection},
|
observables::{Observable, ObservableCollection},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -33,7 +34,7 @@ impl Graph {
|
||||||
.series
|
.series
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| Observable::discover(proto, &s.name, &s.metrics))
|
.map(|s| Observable::discover(proto, &s.name, &s.metrics))
|
||||||
.collect::<Result<Vec<Observable>, ProtocolError>>()
|
.collect::<Result<Vec<Observable>, WaybarCollectdError>>()
|
||||||
.expect("Could not discover required metrics"),
|
.expect("Could not discover required metrics"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue