diff --git a/PVE/API2/OpenVZ.pm b/PVE/API2/OpenVZ.pm index a6f26dc1..2788da25 100644 --- a/PVE/API2/OpenVZ.pm +++ b/PVE/API2/OpenVZ.pm @@ -582,6 +582,7 @@ __PACKAGE__->register_method({ my $res = [ { subdir => 'current' }, + { subdir => 'ubc' }, { subdir => 'start' }, { subdir => 'stop' }, ]; @@ -615,6 +616,45 @@ __PACKAGE__->register_method({ 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({ name => 'vm_start', path => '{vmid}/status/start', diff --git a/PVE/OpenVZ.pm b/PVE/OpenVZ.pm index 96a010dc..f18a43a7 100644 --- a/PVE/OpenVZ.pm +++ b/PVE/OpenVZ.pm @@ -59,6 +59,32 @@ sub load_config { 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 { my ($vmid) = @_;