diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2014-02-14 02:59:05 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2014-02-14 03:07:36 +0100 |
commit | 81fbfaeefefd9d3ada0ef4e826f48ccce7004062 (patch) | |
tree | 6028fad908a1a05e6125dc06b022663eafcebbf5 /lib/VServer.pm | |
parent | 7d33137a77f2b817ccbe78ce67fe7411ed74f768 (diff) | |
download | vserver-perl-81fbfaeefefd9d3ada0ef4e826f48ccce7004062.tar.gz vserver-perl-81fbfaeefefd9d3ada0ef4e826f48ccce7004062.tar.bz2 vserver-perl-81fbfaeefefd9d3ada0ef4e826f48ccce7004062.zip |
get_loadavg now returns a hashref
Diffstat (limited to 'lib/VServer.pm')
-rw-r--r-- | lib/VServer.pm | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/VServer.pm b/lib/VServer.pm index acbb8af..bd823b9 100644 --- a/lib/VServer.pm +++ b/lib/VServer.pm @@ -82,18 +82,22 @@ sub get_name($) { sub get_loadavg($) { my $id = shift; my $dir = get_proc_dir($id) || return undef; - my @load = undef; + my %load = (); 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); + %load = ( + load1 => $1, + load5 => $2, + load15 => $3 + ); last; } } close($cvirt); - return @load; + return \%load; } sub get_mem($) { @@ -205,11 +209,11 @@ 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. +Returns the three (load1, load5, load15) load values as hasref 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 a hashref or +B<undef> if any error occurs. =item B<get_mem($context)> |