diff options
-rw-r--r-- | lib/VServer.pm | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/VServer.pm b/lib/VServer.pm index b586a9e..1ef31aa 100644 --- a/lib/VServer.pm +++ b/lib/VServer.pm @@ -1,7 +1,7 @@ #!/usr/bin/perl -T package VServer; -our $VERSION = '1.4'; +our $VERSION = '1.5'; use strict; use warnings; @@ -78,6 +78,24 @@ sub get_name($) { return $name; } +sub get_loadavg($) { + my $id = shift; + my $dir = get_proc_dir($id) || return undef; + my @load = undef; + + open(my $cvirt, "<", "$dir/cvirt") || return undef; + while (<$cvirt>) { + if ($_ =~ m/^loadavg:\s*([0-9.]+)\s*([0-9.]+)\s*([0-9.]+)$/) { + @load = ($1, $2, $3); + last; + } + } + close($cvirt); + + return @load; +} + + 1; __END__ @@ -137,6 +155,14 @@ This uses B<get_config_dir($context)> and reading the name file inside the config directory. If any error occurs, B<undef> is returned. +=item B<get_loadavg($context)> + +Returns the three (load1, load5, load15) load values for the vserver +specified by the given context id. The functions reads the B<cvirt> +file inside the I</proc> directory of the vserver and parses the +loadavg values. The function returns the three values or B<undef> +if any error occurs. + =back =head1 AUTHORS |