From 4fa99a164d1c0bb1a81487ffa0a57e967e62d59c Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Tue, 6 Aug 2024 14:59:55 +0200 Subject: [PATCH] rrd_cache: use new callback for RRD creation Some changes in `promox-rrd` now require a separate callback for creating a new RRD. Signed-off-by: Lukas Wagner --- src/rrd_cache.rs | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/rrd_cache.rs b/src/rrd_cache.rs index 02bb9372..7ca280de 100644 --- a/src/rrd_cache.rs +++ b/src/rrd_cache.rs @@ -9,7 +9,7 @@ use std::path::Path; use anyhow::{format_err, Error}; use once_cell::sync::OnceCell; -use proxmox_rrd::rrd::{AggregationFn, DataSourceType, Database}; +use proxmox_rrd::rrd::{AggregationFn, DataSourceType, Database, Archive}; use proxmox_rrd::Cache; use proxmox_sys::fs::CreateOptions; @@ -49,6 +49,7 @@ pub fn initialize_rrd_cache() -> Result<&'static Cache, Error> { Some(dir_options), apply_interval, load_callback, + create_callback, )?; RRD_CACHE @@ -58,22 +59,37 @@ pub fn initialize_rrd_cache() -> Result<&'static Cache, Error> { Ok(RRD_CACHE.get().unwrap()) } -fn load_callback(path: &Path, _rel_path: &str, dst: DataSourceType) -> Database { +fn load_callback(path: &Path, _rel_path: &str) -> Option { match Database::load(path, true) { - Ok(rrd) => rrd, + Ok(rrd) => Some(rrd), Err(err) => { if err.kind() != std::io::ErrorKind::NotFound { - log::warn!( - "overwriting RRD file {:?}, because of load error: {}", - path, - err - ); + log::warn!("overwriting RRD file {path:?}, because of load error: {err}",); } - Cache::create_proxmox_backup_default_rrd(dst) + None } } } +fn create_callback(dst: DataSourceType) -> Database { + let rra_list = vec![ + // 1 min * 1440 => 1 day + Archive::new(AggregationFn::Average, 60, 1440), + Archive::new(AggregationFn::Maximum, 60, 1440), + // 30 min * 1440 => 30 days ~ 1 month + Archive::new(AggregationFn::Average, 30 * 60, 1440), + Archive::new(AggregationFn::Maximum, 30 * 60, 1440), + // 6 h * 1440 => 360 days ~ 1 year + Archive::new(AggregationFn::Average, 6 * 3600, 1440), + Archive::new(AggregationFn::Maximum, 6 * 3600, 1440), + // 1 week * 570 => 10 years + Archive::new(AggregationFn::Average, 7 * 86400, 570), + Archive::new(AggregationFn::Maximum, 7 * 86400, 570), + ]; + + Database::new(dst, rra_list) +} + /// Extracts data for the specified time frame from from RRD cache pub fn extract_rrd_data( basedir: &str,