Fix #1542: show storage utilization per pool
- get storage utilization per pool - use librados2-perl for pool status - add librados2-perl as build-depends and depends in debian/control Signed-off-by: Alwin Antreich <a.antreich@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
32c0a1d59b
commit
41aacc6cde
@ -1065,8 +1065,7 @@ sub storage_info {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($total, $avail, $used, $active);
|
my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); };
|
||||||
eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
|
|
||||||
warn $@ if $@;
|
warn $@ if $@;
|
||||||
next if !$active;
|
next if !$active;
|
||||||
$info->{$storeid}->{total} = int($total);
|
$info->{$storeid}->{total} = int($total);
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use Net::IP;
|
|||||||
use PVE::Tools qw(run_command trim);
|
use PVE::Tools qw(run_command trim);
|
||||||
use PVE::Storage::Plugin;
|
use PVE::Storage::Plugin;
|
||||||
use PVE::JSONSchema qw(get_standard_option);
|
use PVE::JSONSchema qw(get_standard_option);
|
||||||
|
use PVE::RADOS;
|
||||||
|
|
||||||
use base qw(PVE::Storage::Plugin);
|
use base qw(PVE::Storage::Plugin);
|
||||||
|
|
||||||
@ -90,6 +91,50 @@ my $rados_cmd = sub {
|
|||||||
return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options);
|
return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
my $ceph_connect_option = sub {
|
||||||
|
my ($scfg, $storeid, %options) = @_;
|
||||||
|
|
||||||
|
my $cmd_option = {};
|
||||||
|
my $ceph_storeid_conf = "/etc/pve/priv/ceph/${storeid}.conf";
|
||||||
|
my $keyring = "/etc/pve/priv/ceph/${storeid}.keyring";
|
||||||
|
my $pveceph_managed = !defined($scfg->{monhost});
|
||||||
|
|
||||||
|
$cmd_option->{ceph_conf} = $pveceph_config if (-e $pveceph_config);
|
||||||
|
|
||||||
|
if (-e $ceph_storeid_conf) {
|
||||||
|
if ($pveceph_managed) {
|
||||||
|
warn "ignoring custom ceph config for storage '$storeid', 'monhost' is not set (assuming pveceph managed cluster)!\n";
|
||||||
|
} else {
|
||||||
|
$cmd_option->{ceph_conf} = $ceph_storeid_conf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cmd_option->{keyring} = $keyring if (-e $keyring);
|
||||||
|
$cmd_option->{auth_supported} = (defined $cmd_option->{keyring}) ? 'cephx' : 'none';
|
||||||
|
$cmd_option->{userid} = $scfg->{username} ? $scfg->{username} : 'admin';
|
||||||
|
$cmd_option->{mon_host} = $hostlist->($scfg->{monhost}, ',') if (defined($scfg->{monhost}));
|
||||||
|
|
||||||
|
if (%options) {
|
||||||
|
foreach my $k (keys %options) {
|
||||||
|
$cmd_option->{$k} = $options{$k};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $cmd_option;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
my $librados_connect = sub {
|
||||||
|
my ($scfg, $storeid, $options) = @_;
|
||||||
|
|
||||||
|
my $librados_config = $ceph_connect_option->($scfg, $storeid);
|
||||||
|
|
||||||
|
my $rados = PVE::RADOS->new(%$librados_config);
|
||||||
|
|
||||||
|
return $rados;
|
||||||
|
};
|
||||||
|
|
||||||
# needed for volumes created using ceph jewel (or higher)
|
# needed for volumes created using ceph jewel (or higher)
|
||||||
my $krbd_feature_disable = sub {
|
my $krbd_feature_disable = sub {
|
||||||
my ($scfg, $storeid, $name) = @_;
|
my ($scfg, $storeid, $name) = @_;
|
||||||
@ -539,28 +584,17 @@ sub list_images {
|
|||||||
sub status {
|
sub status {
|
||||||
my ($class, $storeid, $scfg, $cache) = @_;
|
my ($class, $storeid, $scfg, $cache) = @_;
|
||||||
|
|
||||||
my $cmd = &$rados_cmd($scfg, $storeid, 'df');
|
|
||||||
|
|
||||||
my $stats = {};
|
my $rados = &$librados_connect($scfg, $storeid);
|
||||||
|
my $df = $rados->mon_command({ prefix => 'df', format => 'json' });
|
||||||
|
|
||||||
my $parser = sub {
|
my ($d) = grep { $_->{name} eq $scfg->{pool} } @{$df->{pools}};
|
||||||
my $line = shift;
|
|
||||||
if ($line =~ m/^\s*total(?:\s|_)(\S+)\s+(\d+)(k|M|G|T)?/) {
|
|
||||||
$stats->{$1} = $2;
|
|
||||||
# luminous has units here..
|
|
||||||
if ($3) {
|
|
||||||
$stats->{$1} *= $rbd_unittobytes->{$3}/1024;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
eval {
|
# max_avail -> max available space for data w/o replication in the pool
|
||||||
run_rbd_command($cmd, errmsg => "rados error", errfunc => sub {}, outfunc => $parser);
|
# bytes_used -> data w/o replication in the pool
|
||||||
};
|
my $free = $d->{stats}->{max_avail};
|
||||||
|
my $used = $d->{stats}->{bytes_used};
|
||||||
my $total = $stats->{space} ? $stats->{space}*1024 : 0;
|
my $total = $used + $free;
|
||||||
my $free = $stats->{avail} ? $stats->{avail}*1024 : 0;
|
|
||||||
my $used = $stats->{used} ? $stats->{used}*1024: 0;
|
|
||||||
my $active = 1;
|
my $active = 1;
|
||||||
|
|
||||||
return ($total, $free, $used, $active);
|
return ($total, $free, $used, $active);
|
||||||
|
|||||||
2
debian/control
vendored
2
debian/control
vendored
@ -5,6 +5,7 @@ Maintainer: Proxmox Support Team <support@proxmox.com>
|
|||||||
Build-Depends: debhelper (>= 7.0.50~),
|
Build-Depends: debhelper (>= 7.0.50~),
|
||||||
libpve-common-perl (>= 5.0-28),
|
libpve-common-perl (>= 5.0-28),
|
||||||
libtest-mockmodule-perl,
|
libtest-mockmodule-perl,
|
||||||
|
librados2-perl,
|
||||||
lintian,
|
lintian,
|
||||||
perl (>= 5.10.0-19),
|
perl (>= 5.10.0-19),
|
||||||
pve-doc-generator,
|
pve-doc-generator,
|
||||||
@ -18,6 +19,7 @@ Depends: cstream,
|
|||||||
libfile-chdir-perl,
|
libfile-chdir-perl,
|
||||||
libnet-dbus-perl,
|
libnet-dbus-perl,
|
||||||
libpve-common-perl (>= 5.0-28),
|
libpve-common-perl (>= 5.0-28),
|
||||||
|
librados2-perl,
|
||||||
lvm2,
|
lvm2,
|
||||||
nfs-common,
|
nfs-common,
|
||||||
perl (>= 5.6.0-16),
|
perl (>= 5.6.0-16),
|
||||||
|
|||||||
Reference in New Issue
Block a user