From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 0EBB51FF187 for ; Mon, 22 Sep 2025 12:17:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0C61B17A05; Mon, 22 Sep 2025 12:18:26 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Mon, 22 Sep 2025 12:15:42 +0200 Message-ID: <20250922101749.34397-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1758536261283 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.022 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Subject: [pve-devel] [PATCH qemu-server] fix #6207: vm status: cache last disk read/write values X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" If disk read/write cannot be queried because of QMP timeout, they should not be reported as 0, but the last value should be re-used. Otherwise, the difference between that reported 0 and the next value, when the stats are queried successfully, will show up as a huge spike in the RRD graphs. Invalidate the cache when there is no PID or the PID changed. Signed-off-by: Fiona Ebner --- src/PVE/QemuServer.pm | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index f7f85436..5940ec38 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -2670,6 +2670,12 @@ our $vmstatus_return_properties = { my $last_proc_pid_stat; +# See bug #6207. If disk write/read cannot be queried because of QMP timeout, they should not be +# reported as 0, but the last value should be re-used. Otherwise, the difference between that +# reported 0 and the next value, when the stats are queried successfully, will show up as a huge +# spike. +my $last_disk_stats = {}; + # get VM status information # This must be fast and should not block ($full == false) # We only query KVM using QMP if $full == true (this can be slow) @@ -2741,6 +2747,14 @@ sub vmstatus { $d->{tags} = $conf->{tags} if defined($conf->{tags}); $res->{$vmid} = $d; + + if ( + $last_disk_stats->{$vmid} + && (!$d->{pid} || $d->{pid} != $last_disk_stats->{$vmid}->{pid}) + ) { + delete($last_disk_stats->{$vmid}); + } + } my $netdev = PVE::ProcFSTools::read_proc_net_dev(); @@ -2815,6 +2829,8 @@ sub vmstatus { return $res if !$full; + my $disk_stats_present = {}; + my $qmpclient = PVE::QMPClient->new(); my $ballooncb = sub { @@ -2862,8 +2878,10 @@ sub vmstatus { $res->{$vmid}->{blockstat}->{$drive_id} = $blockstat->{stats}; } - $res->{$vmid}->{diskread} = $totalrdbytes; - $res->{$vmid}->{diskwrite} = $totalwrbytes; + $res->{$vmid}->{diskread} = $last_disk_stats->{$vmid}->{diskread} = $totalrdbytes; + $res->{$vmid}->{diskwrite} = $last_disk_stats->{$vmid}->{diskwrite} = $totalwrbytes; + $last_disk_stats->{$vmid}->{pid} = $res->{$vmid}->{pid}; + $disk_stats_present->{$vmid} = 1; }; my $machinecb = sub { @@ -2925,7 +2943,13 @@ sub vmstatus { foreach my $vmid (keys %$list) { next if $opt_vmid && ($vmid ne $opt_vmid); + $res->{$vmid}->{qmpstatus} = $res->{$vmid}->{status} if !$res->{$vmid}->{qmpstatus}; + + if (!$disk_stats_present->{$vmid} && $last_disk_stats->{$vmid}) { + $res->{$vmid}->{diskread} = $last_disk_stats->{$vmid}->{diskread}; + $res->{$vmid}->{diskwrite} = $last_disk_stats->{$vmid}->{diskwrite}; + } } return $res; -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel