proxmox-rrd: use log crate instead of eprintln, avoid duplicate logs
This commit is contained in:
parent
18e8bc17e4
commit
3def6bfc64
@ -8,6 +8,7 @@ description = "Simple RRD database implementation."
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
|
log = "0.4"
|
||||||
|
|
||||||
proxmox = { version = "0.13.5", features = ["api-macro"] }
|
proxmox = { version = "0.13.5", features = ["api-macro"] }
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ impl RRDCache {
|
|||||||
Ok(rrd) => rrd,
|
Ok(rrd) => rrd,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err.kind() != std::io::ErrorKind::NotFound {
|
if err.kind() != std::io::ErrorKind::NotFound {
|
||||||
eprintln!("overwriting RRD file {:?}, because of load error: {}", path, err);
|
log::warn!("overwriting RRD file {:?}, because of load error: {}", path, err);
|
||||||
}
|
}
|
||||||
RRD::new(dst)
|
RRD::new(dst)
|
||||||
},
|
},
|
||||||
|
@ -118,7 +118,7 @@ impl RRA {
|
|||||||
(last_value*(self.last_count as f64))/(new_count as f64)
|
(last_value*(self.last_count as f64))/(new_count as f64)
|
||||||
+ value/(new_count as f64)
|
+ value/(new_count as f64)
|
||||||
} else {
|
} else {
|
||||||
eprintln!("rrdb update failed - unknown CF");
|
log::error!("rrdb update failed - unknown CF");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.data[index] = new_value;
|
self.data[index] = new_value;
|
||||||
@ -127,15 +127,18 @@ impl RRA {
|
|||||||
self.last_update = time;
|
self.last_update = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, time: f64, mut value: f64) {
|
fn update(&mut self, time: f64, mut value: f64, log_time_in_past: &mut bool) {
|
||||||
|
|
||||||
if time <= self.last_update {
|
if time <= self.last_update {
|
||||||
eprintln!("rrdb update failed - time in past ({} < {})", time, self.last_update);
|
if *log_time_in_past {
|
||||||
|
log::warn!("rrdb update failed - time in past ({} < {})", time, self.last_update);
|
||||||
|
*log_time_in_past = false; // avoid logging this multiple times inside a RRD
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if value.is_nan() {
|
if value.is_nan() {
|
||||||
eprintln!("rrdb update failed - new value is NAN");
|
log::warn!("rrdb update failed - new value is NAN");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,12 +150,12 @@ impl RRA {
|
|||||||
let diff = if self.counter_value.is_nan() {
|
let diff = if self.counter_value.is_nan() {
|
||||||
0.0
|
0.0
|
||||||
} else if is_counter && value < 0.0 {
|
} else if is_counter && value < 0.0 {
|
||||||
eprintln!("rrdb update failed - got negative value for counter");
|
log::warn!("rrdb update failed - got negative value for counter");
|
||||||
return;
|
return;
|
||||||
} else if is_counter && value < self.counter_value {
|
} else if is_counter && value < self.counter_value {
|
||||||
// Note: We do not try automatic overflow corrections
|
// Note: We do not try automatic overflow corrections
|
||||||
self.counter_value = value;
|
self.counter_value = value;
|
||||||
eprintln!("rrdb update failed - conter overflow/reset detected");
|
log::warn!("rrdb update failed - conter overflow/reset detected");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
value - self.counter_value
|
value - self.counter_value
|
||||||
@ -339,19 +342,27 @@ impl RRD {
|
|||||||
///
|
///
|
||||||
/// Note: This does not call [Self::save].
|
/// Note: This does not call [Self::save].
|
||||||
pub fn update(&mut self, time: f64, value: f64) {
|
pub fn update(&mut self, time: f64, value: f64) {
|
||||||
self.hour_avg.update(time, value);
|
|
||||||
self.hour_max.update(time, value);
|
|
||||||
|
|
||||||
self.day_avg.update(time, value);
|
if value.is_nan() {
|
||||||
self.day_max.update(time, value);
|
log::warn!("rrdb update failed - new value is NAN");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.week_avg.update(time, value);
|
let mut log_time_in_past = true;
|
||||||
self.week_max.update(time, value);
|
|
||||||
|
|
||||||
self.month_avg.update(time, value);
|
self.hour_avg.update(time, value, &mut log_time_in_past);
|
||||||
self.month_max.update(time, value);
|
self.hour_max.update(time, value, &mut log_time_in_past);
|
||||||
|
|
||||||
self.year_avg.update(time, value);
|
self.day_avg.update(time, value, &mut log_time_in_past);
|
||||||
self.year_max.update(time, value);
|
self.day_max.update(time, value, &mut log_time_in_past);
|
||||||
|
|
||||||
|
self.week_avg.update(time, value, &mut log_time_in_past);
|
||||||
|
self.week_max.update(time, value, &mut log_time_in_past);
|
||||||
|
|
||||||
|
self.month_avg.update(time, value, &mut log_time_in_past);
|
||||||
|
self.month_max.update(time, value, &mut log_time_in_past);
|
||||||
|
|
||||||
|
self.year_avg.update(time, value, &mut log_time_in_past);
|
||||||
|
self.year_max.update(time, value, &mut log_time_in_past);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user