From 72a9d09175f1fee539ad9f67950d67e240312328 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 12 Feb 2014 03:44:18 +0100 Subject: get_loadavg: add function --- lib/VServer.pm | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 and reading the name file inside the config directory. If any error occurs, B is 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. + =back =head1 AUTHORS -- cgit v1.2.3-1-g7c22