api: datastore status: refactor reused rrd get-data code into closure

Nicer and shorter than just using a variable for the common parameters

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-05-21 13:19:02 +02:00
parent 90761f0f62
commit 64e0786aa9
1 changed files with 7 additions and 14 deletions

View File

@ -21,7 +21,7 @@ use crate::api2::types::{
Authid, Authid,
}; };
use crate::backup::{DataStore}; use crate::backup::DataStore;
use crate::config::datastore; use crate::config::datastore;
use crate::tools::statistics::{linear_regression}; use crate::tools::statistics::{linear_regression};
use crate::config::cached_user_info::CachedUserInfo; use crate::config::cached_user_info::CachedUserInfo;
@ -110,24 +110,17 @@ pub fn datastore_status(
let rrd_dir = format!("datastore/{}", store); let rrd_dir = format!("datastore/{}", store);
let now = proxmox::tools::time::epoch_f64(); let now = proxmox::tools::time::epoch_f64();
let rrd_resolution = RRDTimeFrameResolution::Month;
let rrd_mode = RRDMode::Average;
let total_res = crate::rrd::extract_cached_data( let get_rrd = |what: &str| crate::rrd::extract_cached_data(
&rrd_dir, &rrd_dir,
"total", what,
now, now,
rrd_resolution, RRDTimeFrameResolution::Month,
rrd_mode, RRDMode::Average,
); );
let used_res = crate::rrd::extract_cached_data( let total_res = get_rrd("total");
&rrd_dir, let used_res = get_rrd("used");
"used",
now,
rrd_resolution,
rrd_mode,
);
if let (Some((start, reso, total_list)), Some((_, _, used_list))) = (total_res, used_res) { if let (Some((start, reso, total_list)), Some((_, _, used_list))) = (total_res, used_res) {
let mut usage_list: Vec<f64> = Vec::new(); let mut usage_list: Vec<f64> = Vec::new();