Commit 41111bdc authored by Dietmar Maurer's avatar Dietmar Maurer

add API for openvz user_beancounters

parent c84fa8ff
...@@ -582,6 +582,7 @@ __PACKAGE__->register_method({ ...@@ -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({ ...@@ -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 { ...@@ -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) = @_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment