mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-14 11:23:44 +00:00
rrd: move creation of serde value into api
there is now a 'extract_cached_data' which just returns the data of the specified field, and an api function that converts a list of fields to the correct serde value this way we do not have to create a serde value in rrd/cache.rs (makes for a better interface) Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
9a860821e4
commit
11cb8cd008
@ -4,7 +4,6 @@ use std::sync::{RwLock};
|
|||||||
|
|
||||||
use anyhow::{format_err, Error};
|
use anyhow::{format_err, Error};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use serde_json::{json, Value};
|
|
||||||
|
|
||||||
use proxmox::tools::fs::{create_path, CreateOptions};
|
use proxmox::tools::fs::{create_path, CreateOptions};
|
||||||
|
|
||||||
@ -103,41 +102,18 @@ pub fn extract_lists(
|
|||||||
Ok((times, result))
|
Ok((times, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extract_data(
|
pub fn extract_cached_data(
|
||||||
base: &str,
|
base: &str,
|
||||||
items: &[&str],
|
name: &str,
|
||||||
|
now: f64,
|
||||||
timeframe: RRDTimeFrameResolution,
|
timeframe: RRDTimeFrameResolution,
|
||||||
mode: RRDMode,
|
mode: RRDMode,
|
||||||
) -> Result<Value, Error> {
|
) -> Option<(u64, u64, Vec<Option<f64>>)> {
|
||||||
|
|
||||||
let now = epoch_now_f64()?;
|
|
||||||
|
|
||||||
let map = RRD_CACHE.read().unwrap();
|
let map = RRD_CACHE.read().unwrap();
|
||||||
|
|
||||||
let mut result = Vec::new();
|
match map.get(&format!("{}/{}", base, name)) {
|
||||||
|
Some(rrd) => Some(rrd.extract_data(now, timeframe, mode)),
|
||||||
for name in items.iter() {
|
None => None,
|
||||||
let rrd = match map.get(&format!("{}/{}", base, name)) {
|
|
||||||
Some(rrd) => rrd,
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
let (start, reso, list) = rrd.extract_data(now, timeframe, mode);
|
|
||||||
let mut t = start;
|
|
||||||
for index in 0..RRD_DATA_ENTRIES {
|
|
||||||
if result.len() <= index {
|
|
||||||
if let Some(value) = list[index] {
|
|
||||||
result.push(json!({ "time": t, *name: value }));
|
|
||||||
} else {
|
|
||||||
result.push(json!({ "time": t }));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Some(value) = list[index] {
|
|
||||||
result[index][name] = value.into();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t += reso;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(result.into())
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user