rrd: add 'extract_lists'

this is an interface to simply get the Vec<Option<f64>> out of rrd
without going through serde values

we return a list of timestamps and a HashMap with the lists we could find
(otherwise it is not in the map)

if no lists could be extracted, the time list is also empty

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-06-09 10:01:11 +02:00 committed by Dietmar Maurer
parent 34020b929e
commit 6cad8ce4ce
1 changed files with 37 additions and 0 deletions

View File

@ -71,6 +71,43 @@ pub fn update_value(rel_path: &str, value: f64, dst: DST, save: bool) -> Result<
Ok(()) Ok(())
} }
/// extracts the lists of the given items and a list of timestamps
pub fn extract_lists(
base: &str,
items: &[&str],
timeframe: RRDTimeFrameResolution,
mode: RRDMode,
) -> Result<(Vec<u64>, HashMap<String, Vec<Option<f64>>>), Error> {
let now = now()?;
let map = RRD_CACHE.read().unwrap();
let mut result = HashMap::new();
let mut times = Vec::new();
for name in items.iter() {
let rrd = match map.get(&format!("{}/{}", base, name)) {
Some(rrd) => rrd,
None => continue,
};
let (start, reso, list) = rrd.extract_data(now, timeframe, mode);
result.insert(name.to_string(), list);
if times.len() == 0 {
let mut t = start;
for _ in 0..RRD_DATA_ENTRIES {
times.push(t);
t += reso;
}
}
}
Ok((times, result))
}
pub fn extract_data( pub fn extract_data(
base: &str, base: &str,
items: &[&str], items: &[&str],