mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-08-08 06:10:41 +00:00
add API for openvz user_beancounters
This commit is contained in:
parent
8786c4fa92
commit
56203bf1f7
@ -582,6 +582,7 @@ __PACKAGE__->register_method({
|
|||||||
|
|
||||||
my $res = [
|
my $res = [
|
||||||
{ subdir => 'current' },
|
{ subdir => 'current' },
|
||||||
|
{ subdir => 'ubc' },
|
||||||
{ subdir => 'start' },
|
{ subdir => 'start' },
|
||||||
{ subdir => 'stop' },
|
{ subdir => 'stop' },
|
||||||
];
|
];
|
||||||
@ -615,6 +616,45 @@ __PACKAGE__->register_method({
|
|||||||
return $vmstatus->{$param->{vmid}};
|
return $vmstatus->{$param->{vmid}};
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
__PACKAGE__->register_method({
|
||||||
|
name => 'vm_user_beancounters',
|
||||||
|
path => '{vmid}/status/ubc',
|
||||||
|
method => 'GET',
|
||||||
|
proxyto => 'node',
|
||||||
|
protected => 1, # openvz /proc entries are only readable by root
|
||||||
|
description => "Get container user_beancounters.",
|
||||||
|
parameters => {
|
||||||
|
additionalProperties => 0,
|
||||||
|
properties => {
|
||||||
|
node => get_standard_option('pve-node'),
|
||||||
|
vmid => get_standard_option('pve-vmid'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
returns => {
|
||||||
|
type => 'array',
|
||||||
|
items => {
|
||||||
|
type => "object",
|
||||||
|
properties => {
|
||||||
|
id => { type => 'string' },
|
||||||
|
held => { type => 'number' },
|
||||||
|
maxheld => { type => 'number' },
|
||||||
|
bar => { type => 'number' },
|
||||||
|
lim => { type => 'number' },
|
||||||
|
failcnt => { type => 'number' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
code => sub {
|
||||||
|
my ($param) = @_;
|
||||||
|
|
||||||
|
# test if VM exists
|
||||||
|
my $conf = PVE::OpenVZ::load_config($param->{vmid});
|
||||||
|
|
||||||
|
my $ubc = PVE::OpenVZ::read_container_beancounters($param->{vmid});
|
||||||
|
|
||||||
|
return PVE::RESTHandler::hash_to_array($ubc, 'id');
|
||||||
|
}});
|
||||||
|
|
||||||
__PACKAGE__->register_method({
|
__PACKAGE__->register_method({
|
||||||
name => 'vm_start',
|
name => 'vm_start',
|
||||||
path => '{vmid}/status/start',
|
path => '{vmid}/status/start',
|
||||||
|
@ -59,6 +59,32 @@ sub load_config {
|
|||||||
return $conf;
|
return $conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub read_container_beancounters {
|
||||||
|
my ($vmid) = @_;
|
||||||
|
|
||||||
|
my $ubc = {};
|
||||||
|
if (my $fh = IO::File->new ("/proc/user_beancounters", "r")) {
|
||||||
|
my $cid;
|
||||||
|
while (defined (my $line = <$fh>)) {
|
||||||
|
if ($line =~ m|\s*((\d+):\s*)?([a-z]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$|) {
|
||||||
|
$cid = $2 if defined($2);
|
||||||
|
next if !$cid || $cid != $vmid;
|
||||||
|
my ($name, $held, $maxheld, $bar, $lim, $failcnt) = (lc($3), $4, $5, $6, $7, $8);
|
||||||
|
$ubc->{$name} = {
|
||||||
|
held => $held,
|
||||||
|
maxheld => $maxheld,
|
||||||
|
bar => $bar,
|
||||||
|
lim => $lim,
|
||||||
|
failcnt => $failcnt,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close($fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ubc;
|
||||||
|
}
|
||||||
|
|
||||||
sub read_container_network_usage {
|
sub read_container_network_usage {
|
||||||
my ($vmid) = @_;
|
my ($vmid) = @_;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user