Thanks for the answer. I've switched from Microsoft Hyper-V to Proxmox, so questions questions.At the moment, disk usage for VMs is not tracked and therefore this value is always displayed as 0%.
There is still an active issue on this problem. Please see this issue on our bug tracker for more information or if you want to contribute.
cp /usr/share/perl5/PVE/QemuServer.pm /opt/QemuServer-original-`date +%Y-%m-%d-%s`.pm
vi /usr/share/perl5/PVE/QemuServer.pm
my $size = PVE::QemuServer::Drive::bootdisk_size($storecfg, $conf);
if (defined($size)) {
$d->{disk} = 0; # no info available
$d->{maxdisk} = $size;
} else {
$d->{disk} = 0;
$d->{maxdisk} = 0;
}
##### CODE TO FETCH VM DISK USAGE FROM CEPH POOL START #####
my @bootdiskorder = split('=', $conf->{boot});
my @bootdiskname = split(';', $bootdiskorder[1]);
my @bootdiskinfo = split(",", $conf->{$bootdiskname[0]});
my @bootdiskdetail = split(":", $bootdiskinfo[0]);
my $bootdiskstorage = $bootdiskdetail[0];
my $bootdiskimage = $bootdiskdetail[1];
if (defined $storecfg->{ids}->{$bootdiskstorage}->{type}) {
my $bootdisktype = $storecfg->{ids}->{$bootdiskstorage}->{type};
my $bootdiskpool = $storecfg->{ids}->{$bootdiskstorage}->{pool};
if ($bootdisktype eq "rbd") {
my $cephrbddiskinfocmd = "rbd disk-usage -p " . $bootdiskpool . " " . $bootdiskimage . " --format=json";
my $cephrbddiskinfo = `$cephrbddiskinfocmd`;
$cephrbddiskinfo =~ s/\n/""/eg;
$cephrbddiskinfo =~ s/\r/""/eg;
$cephrbddiskinfo =~ s/\t/""/eg;
$cephrbddiskinfo =~ s/\0/""/eg;
$cephrbddiskinfo =~ s/^[a-zA-z0-9,]//g;
my $total_used_size = 0;
if ($cephrbddiskinfo =~ /$bootdiskimage/) {
my $cephrbddiskinfoarray = decode_json($cephrbddiskinfo);
foreach my $image (@{$cephrbddiskinfoarray->{'images'}}) {
if (defined $image->{'used_size'}) {
$total_used_size += $image->{'used_size'};
}
}
$d->{disk} = $total_used_size;
}
}
}
##### CODE TO FETCH VM DISK USAGE FROM CEPH POOL END #####
systemctl restart pvestatd.service
tail -f /var/log/syslog
I hope your storage uses Ceph RBD, as the code is currently designed exclusively for Ceph Storage (I will publish ZFS Storage compatibility soon), authored by me. Additionally, for syslog, which is not installed by default in PVE8, you will need to install the rsyslog package.
##### CODE TO FETCH VM DISK USAGE FROM CEPH + ZFS POOL START #####
my @bootdiskorder = split('=', $conf->{boot});
my @bootdiskname = split(';', $bootdiskorder[1]);
my @bootdiskinfo = split(",", $conf->{$bootdiskname[0]});
my @bootdiskdetail = split(":", $bootdiskinfo[0]);
my $bootdiskstorage = $bootdiskdetail[0];
my $bootdiskimage = $bootdiskdetail[1];
if (defined $storecfg->{ids}->{$bootdiskstorage}->{type}) {
my $bootdisktype = $storecfg->{ids}->{$bootdiskstorage}->{type};
my $bootdiskpool = $storecfg->{ids}->{$bootdiskstorage}->{pool};
if ($bootdisktype eq "zfspool") {
my $zfsdiskinfocmd ="zfs get -H -p -oname,value used ".$bootdiskpool."/".$bootdiskimage;
my $zfsdiskinfo=`$zfsdiskinfocmd`;
$zfsdiskinfo =~ s/\n/""/eg;
$zfsdiskinfo =~ s/\r/""/eg;
my $total_used_size = 0;
if ($zfsdiskinfo =~ /$bootdiskimage/) {
my @zfsdiskbytes=split("\t",$zfsdiskinfo);
$total_used_size=$zfsdiskbytes[1];
}
$d->{disk} = $total_used_size;
}
if ($bootdisktype eq "rbd") {
my $cephrbddiskinfocmd = "rbd disk-usage -p " . $bootdiskpool . " " . $bootdiskimage . " --format=json";
my $cephrbddiskinfo = `$cephrbddiskinfocmd`;
$cephrbddiskinfo =~ s/\n/""/eg;
$cephrbddiskinfo =~ s/\r/""/eg;
$cephrbddiskinfo =~ s/\t/""/eg;
$cephrbddiskinfo =~ s/\0/""/eg;
$cephrbddiskinfo =~ s/^[a-zA-z0-9,]//g;
my $total_used_size = 0;
if ($cephrbddiskinfo =~ /$bootdiskimage/) {
my $cephrbddiskinfoarray = decode_json($cephrbddiskinfo);
foreach my $image (@{$cephrbddiskinfoarray->{'images'}}) {
if (defined $image->{'used_size'}) {
$total_used_size += $image->{'used_size'};
}
}
$d->{disk} = $total_used_size;
}
}
}
##### CODE TO FETCH VM DISK USAGE FROM CEPH POOL END #####
Maybe the clue that it's not implemented already should tip you off that it is not as easy as it seems to. Using the disk usage from qemu is just wrong, as pointed out here. It's the same with the memory usage.So looking through this and other threads, and at the bug report it seems this issue has been going on for 5 years. For such a basic hypervisor functionality is there any way to get this looked at with more priority? Not to be obtuse, but we're paying full licensing for 7 servers and this being outstanding and a weird workaround being the only fix is disappointing.
If there is a recommended workaround that customers are expected to generally perform then I don't think that "it's not as easy as it seems" holds much water. That could be automated behind the scenes.Maybe the clue that it's not implemented already should tip you off that it is not as easy as it seems to. Using the disk usage from qemu is just wrong, as pointed out here. It's the same with the memory usage.
There is no workaround, that's the problem. For e.g. thick-LVM, there will always be 100% disk usage. I don't think that "information" will help anyone.If there is a recommended workaround that customers are expected to generally perform then I don't think that "it's not as easy as it seems" holds much water. That could be automated behind the scenes.
I am not smart enough to understand what is going on yet as I am learning but I was unable to get the storage info for my redhat 9 vms specifically. all others seems to be fine. They all have the qemu-agent. Any way to troubleshoot this?Complete code with ceph rbd and ZFS is as below , keep in mind zfs would show more size than actual allocated , example 100GB is take as 155GB , is snapshot is attached.
Code:##### CODE TO FETCH VM DISK USAGE FROM CEPH + ZFS POOL START ##### my @bootdiskorder = split('=', $conf->{boot}); my @bootdiskname = split(';', $bootdiskorder[1]); my @bootdiskinfo = split(",", $conf->{$bootdiskname[0]}); my @bootdiskdetail = split(":", $bootdiskinfo[0]); my $bootdiskstorage = $bootdiskdetail[0]; my $bootdiskimage = $bootdiskdetail[1]; if (defined $storecfg->{ids}->{$bootdiskstorage}->{type}) { my $bootdisktype = $storecfg->{ids}->{$bootdiskstorage}->{type}; my $bootdiskpool = $storecfg->{ids}->{$bootdiskstorage}->{pool}; if ($bootdisktype eq "zfspool") { my $zfsdiskinfocmd ="zfs get -H -p -oname,value used ".$bootdiskpool."/".$bootdiskimage; my $zfsdiskinfo=`$zfsdiskinfocmd`; $zfsdiskinfo =~ s/\n/""/eg; $zfsdiskinfo =~ s/\r/""/eg; my $total_used_size = 0; if ($zfsdiskinfo =~ /$bootdiskimage/) { my @zfsdiskbytes=split("\t",$zfsdiskinfo); $total_used_size=$zfsdiskbytes[1]; } $d->{disk} = $total_used_size; } if ($bootdisktype eq "rbd") { my $cephrbddiskinfocmd = "rbd disk-usage -p " . $bootdiskpool . " " . $bootdiskimage . " --format=json"; my $cephrbddiskinfo = `$cephrbddiskinfocmd`; $cephrbddiskinfo =~ s/\n/""/eg; $cephrbddiskinfo =~ s/\r/""/eg; $cephrbddiskinfo =~ s/\t/""/eg; $cephrbddiskinfo =~ s/\0/""/eg; $cephrbddiskinfo =~ s/^[a-zA-z0-9,]//g; my $total_used_size = 0; if ($cephrbddiskinfo =~ /$bootdiskimage/) { my $cephrbddiskinfoarray = decode_json($cephrbddiskinfo); foreach my $image (@{$cephrbddiskinfoarray->{'images'}}) { if (defined $image->{'used_size'}) { $total_used_size += $image->{'used_size'}; } } $d->{disk} = $total_used_size; } } } ##### CODE TO FETCH VM DISK USAGE FROM CEPH POOL END #####
my $zfsdiskinfocmd ="zfs get -H -p -oname,value used ".$bootdiskpool."/".$bootdiskimage;
my $size = PVE::QemuServer::Drive::bootdisk_size($storecfg, $conf);
if (defined($size)) {
$d->{disk} = 0; # no info available
$d->{maxdisk} = $size;
} else {
$d->{disk} = 0;
$d->{maxdisk} = 0;
}
if (defined $storecfg->{ids}->{$bootdiskstorage}->{type}) {
We use essential cookies to make this site work, and optional cookies to enhance your experience.