X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2FUtils.pm;h=9666d81d3e7ef3d1c3e28dd4a8d67e3bd1afd357;hb=f5e61610169aa1f1041ca359e8b0f5b3a04828ef;hp=a21d996ea1ae7cd00d50bb6c566838cfa1bb191c;hpb=2334ee487207843203bb75ab9744f2702f52cdce;p=clearscm.git diff --git a/lib/Utils.pm b/lib/Utils.pm index a21d996..9666d81 100644 --- a/lib/Utils.pm +++ b/lib/Utils.pm @@ -74,6 +74,7 @@ our @EXPORT = qw ( GetChildren GetPassword InArray + LoadAvg PageOutput PipeOutput PipeOutputArray @@ -430,6 +431,60 @@ Returns: return $FALSE; } # InArray +sub LoadAvg () { + +=pod + +=head2 LoadAvg () + +Return an array of the 1, 5, and 15 minute load averages. + +Parameters: + +=for html
+ +=over + +=item none + +=back + +=for html+ +Returns: + +=for html
+ +=over + +=item An array of the 1, 5, and 15 minute load averages in a list context. +In a scalar context just the 1 minute load average. + +=back + +=for html+ +=cut + + # TODO: Make it work on Windows... + return if $^O =~ /win/i; + + open my $loadAvg, '/proc/loadavg' + or croak "Unable to open /proc/loadavg\n"; + + my $load = <$loadAvg>; + + close $loadAvg; + + my @loadAvgs = split /\s/, $load; + + if (wantarray) { + return @loadAvgs; + } else { + return $loadAvgs[0]; # This is the 1 minute average + } +} # LoadAvg + our $pipe; sub StartPipe ($;$) {