forked from Proxmox/proxmox
proxmox-rrd: remove dependency to proxmox-rrd-api-types
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
bc68dee171
commit
cf097c5a89
@ -17,5 +17,3 @@ serde_cbor = "0.11.1"
|
||||
proxmox = { version = "0.14.0" }
|
||||
proxmox-time = "1"
|
||||
proxmox-schema = { version = "1", features = [ "api-macro" ] }
|
||||
|
||||
proxmox-rrd-api-types = { path = "../proxmox-rrd-api-types" }
|
||||
|
@ -11,8 +11,6 @@ use nix::fcntl::OFlag;
|
||||
|
||||
use proxmox::tools::fs::{atomic_open_or_create_file, create_path, CreateOptions};
|
||||
|
||||
use proxmox_rrd_api_types::{RRDMode, RRDTimeFrameResolution};
|
||||
|
||||
use crate::rrd::{DST, CF, RRD, RRA};
|
||||
|
||||
const RRD_JOURNAL_NAME: &str = "rrd.journal";
|
||||
@ -280,35 +278,23 @@ impl RRDCache {
|
||||
}
|
||||
|
||||
/// Extract data from cached RRD
|
||||
///
|
||||
/// `start`: Start time. If not sepecified, we simply extract 10 data points.
|
||||
/// `end`: End time. Default is to use the current time.
|
||||
pub fn extract_cached_data(
|
||||
&self,
|
||||
base: &str,
|
||||
name: &str,
|
||||
now: f64,
|
||||
timeframe: RRDTimeFrameResolution,
|
||||
mode: RRDMode,
|
||||
cf: CF,
|
||||
resolution: u64,
|
||||
start: Option<u64>,
|
||||
end: Option<u64>,
|
||||
) -> Result<Option<(u64, u64, Vec<Option<f64>>)>, Error> {
|
||||
|
||||
let state = self.state.read().unwrap();
|
||||
|
||||
let cf = match mode {
|
||||
RRDMode::Max => CF::Maximum,
|
||||
RRDMode::Average => CF::Average,
|
||||
};
|
||||
|
||||
let now = now as u64;
|
||||
|
||||
let (start, resolution) = match timeframe {
|
||||
RRDTimeFrameResolution::Hour => (now - 3600, 60),
|
||||
RRDTimeFrameResolution::Day => (now - 3600*24, 60),
|
||||
RRDTimeFrameResolution::Week => (now - 3600*24*7, 30*60),
|
||||
RRDTimeFrameResolution::Month => (now - 3600*24*30, 30*60),
|
||||
RRDTimeFrameResolution::Year => (now - 3600*24*365, 6*60*60),
|
||||
RRDTimeFrameResolution::Decade => (now - 10*3600*24*366, 7*86400),
|
||||
};
|
||||
|
||||
match state.rrd_map.get(&format!("{}/{}", base, name)) {
|
||||
Some(rrd) => Ok(Some(rrd.extract_data(start, now, cf, resolution)?)),
|
||||
Some(rrd) => Ok(Some(rrd.extract_data(cf, resolution, start, end)?)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
@ -339,12 +339,15 @@ impl RRD {
|
||||
///
|
||||
/// This selects the RRA with specified [CF] and (minimum)
|
||||
/// resolution, and extract data from `start` to `end`.
|
||||
///
|
||||
/// `start`: Start time. If not sepecified, we simply extract 10 data points.
|
||||
/// `end`: End time. Default is to use the current time.
|
||||
pub fn extract_data(
|
||||
&self,
|
||||
start: u64,
|
||||
end: u64,
|
||||
cf: CF,
|
||||
resolution: u64,
|
||||
start: Option<u64>,
|
||||
end: Option<u64>,
|
||||
) -> Result<(u64, u64, Vec<Option<f64>>), Error> {
|
||||
|
||||
let mut rra: Option<&RRA> = None;
|
||||
@ -362,7 +365,11 @@ impl RRD {
|
||||
}
|
||||
|
||||
match rra {
|
||||
Some(rra) => Ok(rra.extract_data(start, end, self.source.last_update)),
|
||||
Some(rra) => {
|
||||
let end = end.unwrap_or_else(|| proxmox_time::epoch_f64() as u64);
|
||||
let start = start.unwrap_or(end - 10*rra.resolution);
|
||||
Ok(rra.extract_data(start, end, self.source.last_update))
|
||||
}
|
||||
None => bail!("unable to find RRA suitable ({:?}:{})", cf, resolution),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user