From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 519C28DAF4 for ; Wed, 9 Nov 2022 15:26:58 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 32E3D1D223 for ; Wed, 9 Nov 2022 15:26:28 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 9 Nov 2022 15:26:26 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8A16042652 for ; Wed, 9 Nov 2022 15:26:26 +0100 (CET) From: Daniel Tschlatscher To: pbs-devel@lists.proxmox.com Date: Wed, 9 Nov 2022 15:25:22 +0100 Message-Id: <20221109142524.549045-1-d.tschlatscher@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.158 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [disk.dev, proxmox-backup-proxy.rs, avail.data, status.rs, status.total] Subject: [pbs-devel] [PATCH backup v5 1/3] fix #4077: Estimated Full metric on ext4 file systems X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2022 14:26:58 -0000 The rrd data now includes tracking the available field in disk usage. The calculation for the estimated_time_full was adapted to use the total for the unpriviliged user, which is the sum of used + available. The total for unprivileged users is preferable, because datastores are always written to by the backup user. Which means that any storage space reserved for root is unusable for our purposes. To avoid resetting the estimate when switching to this new version, the backend will try to use the available value to calculate the unprivileged total. When that is not an option, it will fall back to using the absolute total. Signed-off-by: Daniel Tschlatscher --- Changes from v4: * Revised the implementation of calculating the estimated_full_date field. The new implementation now tries to calculate the total with the new rrd field 'available' + 'used', and if that fails, falls back to using the 'total' that was used up until now. src/api2/status.rs | 49 ++++++++++++++++----------------- src/bin/proxmox-backup-proxy.rs | 2 ++ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/api2/status.rs b/src/api2/status.rs index 50d401c2..87450d63 100644 --- a/src/api2/status.rs +++ b/src/api2/status.rs @@ -86,42 +86,39 @@ pub async fn datastore_status( let total_res = get_rrd("total")?; let used_res = get_rrd("used")?; + let avail_res = get_rrd("available")?; - if let ( - Some(proxmox_rrd::Entry { - start, - resolution, - data: total_list, - }), - Some(proxmox_rrd::Entry { - data: used_list, .. - }), - ) = (total_res, used_res) - { + if let Some(((total_entry, used), avail)) = total_res.zip(used_res).zip(avail_res) { let mut usage_list: Vec = Vec::new(); let mut time_list: Vec = Vec::new(); let mut history = Vec::new(); - for (idx, used) in used_list.iter().enumerate() { - let total = if idx < total_list.len() { - total_list[idx] + for (idx, used) in used.data.iter().enumerate() { + let used = match used { + Some(used) => used, + _ => { + history.push(None); + continue; + } + }; + + let total = if idx < avail.data.len() && avail.data[idx].is_some() { + avail.data[idx].unwrap() + used + } else if idx < total_entry.data.len() && total_entry.data[idx].is_some() { + total_entry.data[idx].unwrap() } else { - None + history.push(None); + continue; }; - match (total, used) { - (Some(total), Some(used)) if total != 0.0 => { - time_list.push(start + (idx as u64) * resolution); - let usage = used / total; - usage_list.push(usage); - history.push(Some(usage)); - } - _ => history.push(None), - } + let usage = used / total; + time_list.push(total_entry.start + (idx as u64) * total_entry.resolution); + usage_list.push(usage); + history.push(Some(usage)); } - entry.history_start = Some(start); - entry.history_delta = Some(resolution); + entry.history_start = Some(total_entry.start); + entry.history_delta = Some(total_entry.resolution); entry.history = Some(history); // we skip the calculation for datastores with not enough data diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 69863481..ec2a8744 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -1255,6 +1255,8 @@ fn rrd_update_disk_stat(disk: &DiskStat, rrd_prefix: &str) { rrd_update_gauge(&rrd_key, status.total as f64); let rrd_key = format!("{}/used", rrd_prefix); rrd_update_gauge(&rrd_key, status.used as f64); + let rrd_key = format!("{}/available", rrd_prefix); + rrd_update_gauge(&rrd_key, status.available as f64); } if let Some(stat) = &disk.dev { -- 2.30.2