Work-Around Fix for Ceph-Storage Usage for VM Usage in Proxmox Virtual Environment (PVE) Cluster.
Would submit the code in bugzilla too (will have to check Development guideline too)
and would be working on ZFS storage too, soon ; as its another popular in PVE Cluster setup,
sharing it if any one want to refer and want to use and want to give feedback.
Introduction:
This document provides step-by-step instructions on implementing a
work-around fix for Ceph-storage utilization in a Proxmox Virtual Environment (PVE) cluster.
Specifically, this fix addresses the issue of displaying boot disk usage for virtual machines (VMs),
including snapshot space, in a Ceph storage configuration.
Procedure:
1. Backup the Original Perl File:
Before making any changes, it is crucial to create a backup of the original Perl file for safety purposes.
Code:
cp /usr/share/perl5/PVE/QemuServer.pm /opt/QemuServer-original-`date +%Y-%m-%d-%s`.pm
2. Edit the Perl File:
Open the Perl file for editing. You can use any text editor, but we will use the example of using the vi editor.
Code:
vi /usr/share/perl5/PVE/QemuServer.pm
Inside the editor, locate the line containing "
{disk}" (approximately around line 2944).
3. Modify the Perl Code:
You will see the following code block:
Code:
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;
}
After the comment line "# no info available," add the following code to retrieve disk usage from the Ceph pool for VMs:
Code:
##### 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 #####
4. Restart the pvestatd Service:
After making the necessary changes, restart the pvestatd service to apply the modifications.
Code:
systemctl restart pvestatd.service
5. Check for Errors:
Monitor the system logs for any potential errors to ensure that the changes were applied without issues.
6. Verify Disk Usage:
If everything is functioning correctly, you should now be able to see the disk usage, including boot disk usage and percentage used, for VMs when they are in the
"ON" state.
I hope it help some, and we get feedback too.
Thanks in advance.
-Deepen.