From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server] fix #6207: vm status: cache last disk read/write values
Date: Mon, 22 Sep 2025 12:15:42 +0200 [thread overview]
Message-ID: <20250922101749.34397-1-f.ebner@proxmox.com> (raw)
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 <f.ebner@proxmox.com>
---
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
reply other threads:[~2025-09-22 10:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250922101749.34397-1-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.