summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-02-12 04:02:54 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-02-12 04:03:19 +0100
commita1052aea4c790463f400d30c1fc5f45650d95bbc (patch)
tree731a62953b400a270069b0a6b099d16e3a9f6bd3
parent72a9d09175f1fee539ad9f67950d67e240312328 (diff)
downloadvserver-perl-a1052aea4c790463f400d30c1fc5f45650d95bbc.tar.gz
vserver-perl-a1052aea4c790463f400d30c1fc5f45650d95bbc.tar.bz2
vserver-perl-a1052aea4c790463f400d30c1fc5f45650d95bbc.zip
get_mem: add function1.6
-rw-r--r--lib/VServer.pm37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/VServer.pm b/lib/VServer.pm
index 1ef31aa..20c8cc1 100644
--- a/lib/VServer.pm
+++ b/lib/VServer.pm
@@ -1,7 +1,7 @@
#!/usr/bin/perl -T
package VServer;
-our $VERSION = '1.5';
+our $VERSION = '1.6';
use strict;
use warnings;
@@ -95,6 +95,31 @@ sub get_loadavg($) {
return @load;
}
+sub get_mem($) {
+ my $context = shift;
+ my $dir = get_proc_dir($context) || return undef;
+ my $ps = POSIX::sysconf(&POSIX::_SC_PAGESIZE) || return undef;
+ my @mem = undef;
+
+ open(my $limit, "<", "$dir/limit") || return undef;
+ while (<$limit>) {
+ if ($_ =~ m/^VM:\s*([0-9]+)\s/) {
+ $mem[0] = $1 * $ps;
+ }
+ elsif ($_ =~ m/RSS:\s*([0-9]+)\s/) {
+ $mem[1] = $1 * $ps;
+ }
+ elsif ($_ =~ m/ANON:\s*([0-9]+)\s/) {
+ $mem[2] = $1 * $ps;
+ }
+ elsif ($_ =~ m/VML:\s*([0-9]+)\s/) {
+ $mem[3] = $1 * $ps;
+ }
+ }
+ close($limit);
+
+ return @mem;
+}
1;
__END__
@@ -163,6 +188,16 @@ 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.
+=item B<get_mem($context)>
+
+Return memory information for the vserver specified by the given
+context id. The function read the B<limit> file inside the I</proc>
+directory of the vserver, parses the memory information and
+multiplies it with the pagesize. The function returns four values
+in the following order I<virtual memory>, I<resident set size>,
+I<anonymous memory> and I<virtual locked memory> or B<undef> if
+any error occurs.
+
=back
=head1 AUTHORS