diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2014-02-12 03:44:18 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2014-02-12 04:02:47 +0100 |
commit | 72a9d09175f1fee539ad9f67950d67e240312328 (patch) | |
tree | f1df8672ce1de3b68bf8e4779df71e0c1d17cf64 /lib | |
parent | ef238be46150e932c65f2bd67aa4325924df2720 (diff) | |
download | vserver-perl-72a9d09175f1fee539ad9f67950d67e240312328.tar.gz vserver-perl-72a9d09175f1fee539ad9f67950d67e240312328.tar.bz2 vserver-perl-72a9d09175f1fee539ad9f67950d67e240312328.zip |
get_loadavg: add function1.5
Diffstat (limited to 'lib')
-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 |