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 err;
|
||||
mod observables;
|
||||
mod runner;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use protocol::{Protocol, ProtocolError};
|
||||
use regex::Regex;
|
||||
|
||||
use crate::config::MetricSpecification;
|
||||
use crate::{config::MetricSpecification, err::WaybarCollectdError};
|
||||
|
||||
pub struct Observable {
|
||||
pub name: String,
|
||||
|
|
@ -23,8 +23,10 @@ impl Observable {
|
|||
proto: &mut Protocol,
|
||||
name: &str,
|
||||
includes: &Vec<MetricSpecification>,
|
||||
) -> Result<Observable, ProtocolError> {
|
||||
let all_values = proto.list()?;
|
||||
) -> Result<Observable, WaybarCollectdError> {
|
||||
let all_values = proto
|
||||
.list()
|
||||
.map_err(|e| WaybarCollectdError::ProtocolError(e))?;
|
||||
let regexes: Vec<MetricRegex> = includes
|
||||
.iter()
|
||||
.map(|i| MetricRegex {
|
||||
|
|
@ -32,7 +34,7 @@ impl Observable {
|
|||
value: i.value.to_string(),
|
||||
})
|
||||
.collect();
|
||||
let filtered_values = all_values
|
||||
let filtered_values: Vec<Metric> = all_values
|
||||
.into_iter()
|
||||
.filter_map(|v| {
|
||||
for r in regexes.iter() {
|
||||
|
|
@ -48,11 +50,15 @@ impl Observable {
|
|||
})
|
||||
.collect();
|
||||
|
||||
if filtered_values.len() == 0 {
|
||||
Err(WaybarCollectdError::NoMatchingMetricFound(name.to_string()))
|
||||
} else {
|
||||
Ok(Observable {
|
||||
name: name.to_string(),
|
||||
metrics: filtered_values,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sample(&self, proto: &mut Protocol) -> Result<f32, ProtocolError> {
|
||||
let results = self
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use core::fmt;
|
||||
|
||||
use draw::{StackedConfig, StackedSeries, StackedSeriesConfig, stacked};
|
||||
use protocol::{Protocol, ProtocolError};
|
||||
use protocol::Protocol;
|
||||
|
||||
use crate::{
|
||||
config::GraphConfig,
|
||||
err::WaybarCollectdError,
|
||||
observables::{Observable, ObservableCollection},
|
||||
};
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ impl Graph {
|
|||
.series
|
||||
.iter()
|
||||
.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"),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue