From 6cad8ce4ce710f247a7f1b819dc3badf845d8c74 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 9 Jun 2020 10:01:11 +0200 Subject: [PATCH] rrd: add 'extract_lists' this is an interface to simply get the Vec> 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 --- src/rrd/cache.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/rrd/cache.rs b/src/rrd/cache.rs index 33e99935..b2ad09cb 100644 --- a/src/rrd/cache.rs +++ b/src/rrd/cache.rs @@ -71,6 +71,43 @@ pub fn update_value(rel_path: &str, value: f64, dst: DST, save: bool) -> Result< 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, HashMap>>), 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( base: &str, items: &[&str],