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 7D5106539A for ; Tue, 3 Nov 2020 06:53:26 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6B7022842E for ; Tue, 3 Nov 2020 06:52:56 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id AAC7528421 for ; Tue, 3 Nov 2020 06:52:55 +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 740EF45D91 for ; Tue, 3 Nov 2020 06:52:55 +0100 (CET) Date: Tue, 3 Nov 2020 06:52:11 +0100 (CET) From: Dietmar Maurer To: Proxmox Backup Server development discussion , Dominik Csapak Message-ID: <846767739.645.1604382732187@webmail.proxmox.com> In-Reply-To: <20201023143233.14949-4-d.csapak@proxmox.com> References: <20201023143233.14949-1-d.csapak@proxmox.com> <20201023143233.14949-4-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.4-Rev12 X-Originating-Client: open-xchange-appsuite X-SPAM-LEVEL: Spam detection results: 0 AWL 0.061 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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. [proxmox.com, datastore.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup 3/3] admin/datastore: add more info to status call 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: Tue, 03 Nov 2020 05:53:26 -0000 This change makes the API call very slow. because it scans over the whole directory tree. Is this really necessary? > On 10/23/2020 4:32 PM Dominik Csapak wrote: > > > add also the snapshot counts as well as the status of the last garbage > collection > > Signed-off-by: Dominik Csapak > --- > src/api2/admin/datastore.rs | 61 +++++++++++++++++++++++++++++++++++-- > 1 file changed, 58 insertions(+), 3 deletions(-) > > diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs > index feeff8af..e1a0aacc 100644 > --- a/src/api2/admin/datastore.rs > +++ b/src/api2/admin/datastore.rs > @@ -423,6 +423,37 @@ pub fn list_snapshots ( > Ok(snapshots) > } > > +// returns a map from type to (group_count, snapshot_count) > +fn get_snaphots_count(store: &DataStore) -> Result, Error> { > + let base_path = store.base_path(); > + let backup_list = BackupInfo::list_backups(&base_path)?; > + let mut groups = HashSet::new(); > + let mut result: HashMap = HashMap::new(); > + for info in backup_list { > + let group = info.backup_dir.group(); > + > + let id = group.backup_id(); > + let backup_type = group.backup_type(); > + > + let mut new_id = false; > + > + if groups.insert(format!("{}-{}", &backup_type, &id)) { > + new_id = true; > + } > + > + if let Some(mut counts) = result.get_mut(backup_type) { > + counts.1 += 1; > + if new_id { > + counts.0 +=1; > + } > + } else { > + result.insert(backup_type.to_string(), (1, 1)); > + } > + } > + > + Ok(result) > +} > + > #[api( > input: { > properties: { > @@ -432,7 +463,21 @@ pub fn list_snapshots ( > }, > }, > returns: { > - type: StorageStatus, > + description: "The overall Datastore status and information.", > + type: Object, > + properties: { > + storage: { > + type: StorageStatus, > + }, > + counts: { > + description: "Group and Snapshot counts per Type", > + type: Object, > + properties: { }, > + }, > + "gc-status": { > + type: GarbageCollectionStatus, > + }, > + }, > }, > access: { > permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_AUDIT | PRIV_DATASTORE_BACKUP, true), > @@ -443,9 +488,19 @@ pub fn status( > store: String, > _info: &ApiMethod, > _rpcenv: &mut dyn RpcEnvironment, > -) -> Result { > +) -> Result { > let datastore = DataStore::lookup_datastore(&store)?; > - crate::tools::disks::disk_usage(&datastore.base_path()) > + let storage_status = crate::tools::disks::disk_usage(&datastore.base_path())?; > + let counts = get_snaphots_count(&datastore)?; > + let gc_status = datastore.last_gc_status(); > + > + let res = json!({ > + "storage": storage_status, > + "counts": counts, > + "gc-status": gc_status, > + }); > + > + Ok(res) > } > > #[api( > -- > 2.20.1 > > > > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel