mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-06 17:52:06 +00:00
rrd: reduce io by saving data only once a minute
This commit is contained in:
parent
a76b0e3c09
commit
1fa3341d68
@ -40,7 +40,7 @@ fn now() -> Result<f64, Error> {
|
|||||||
Ok(time.as_secs_f64())
|
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);
|
let mut path = PathBuf::from(PBS_RRD_BASEDIR);
|
||||||
path.push(rel_path);
|
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) {
|
if let Some(rrd) = map.get_mut(rel_path) {
|
||||||
rrd.update(now, value);
|
rrd.update(now, value);
|
||||||
rrd.save(&path)?;
|
if save { rrd.save(&path)?; }
|
||||||
} else {
|
} else {
|
||||||
let mut rrd = match RRD::load(&path) {
|
let mut rrd = match RRD::load(&path) {
|
||||||
Ok(rrd) => rrd,
|
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.update(now, value);
|
||||||
rrd.save(&path)?;
|
if save { rrd.save(&path)?; }
|
||||||
map.insert(rel_path.into(), rrd);
|
map.insert(rel_path.into(), rrd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user