From 81fbfaeefefd9d3ada0ef4e826f48ccce7004062 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 14 Feb 2014 02:59:05 +0100 Subject: get_loadavg now returns a hashref --- lib/VServer.pm | 20 ++++++++++++-------- 1 file 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 -Returns the three (load1, load5, load15) load values for the vserver -specified by the given context id. The functions reads the B -file inside the I directory of the vserver and parses the -loadavg values. The function returns the three values or B -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 file inside the I directory of the vserver and +parses the loadavg values. The function returns a hashref or +B if any error occurs. =item B -- cgit v1.2.3-1-g7c22