rrd: reduce io by saving data only once a minute

This commit is contained in:
Dietmar Maurer
2020-05-29 09:16:13 +02:00
parent a8d7033cb2
commit 013fa7bbcb
2 changed files with 34 additions and 29 deletions

View File

@ -40,7 +40,7 @@ fn now() -> Result<f64, Error> {
Ok(time.as_secs_f64())
}
pub fn update_value(rel_path: &str, value: f64, dst: DST) -> Result<(), Error> {
pub fn update_value(rel_path: &str, value: f64, dst: DST, save: bool) -> Result<(), Error> {
let mut path = PathBuf::from(PBS_RRD_BASEDIR);
path.push(rel_path);
@ -52,7 +52,7 @@ pub fn update_value(rel_path: &str, value: f64, dst: DST) -> Result<(), Error> {
if let Some(rrd) = map.get_mut(rel_path) {
rrd.update(now, value);
rrd.save(&path)?;
if save { rrd.save(&path)?; }
} else {
let mut rrd = match RRD::load(&path) {
Ok(rrd) => rrd,
@ -64,7 +64,7 @@ pub fn update_value(rel_path: &str, value: f64, dst: DST) -> Result<(), Error> {
},
};
rrd.update(now, value);
rrd.save(&path)?;
if save { rrd.save(&path)?; }
map.insert(rel_path.into(), rrd);
}