summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-02-12 04:36:40 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-02-12 04:36:40 +0100
commit4e8d0d88f6dfa9208c07830112dc97f3f7500bd8 (patch)
tree0c6aea3e1f872ca92f6c853173d1a251e4ddc57b
parent338f2b80610a33ae7e50f14978a80e11de7a9d6a (diff)
downloadvserver-perl-4e8d0d88f6dfa9208c07830112dc97f3f7500bd8.tar.gz
vserver-perl-4e8d0d88f6dfa9208c07830112dc97f3f7500bd8.tar.bz2
vserver-perl-4e8d0d88f6dfa9208c07830112dc97f3f7500bd8.zip
get_net: add function1.8
-rw-r--r--lib/VServer.pm49
1 files changed, 48 insertions, 1 deletions
diff --git a/lib/VServer.pm b/lib/VServer.pm
index 4f19b2f..9a6f9ac 100644
--- a/lib/VServer.pm
+++ b/lib/VServer.pm
@@ -1,7 +1,7 @@
#!/usr/bin/perl -T
package VServer;
-our $VERSION = '1.7';
+our $VERSION = '1.8';
use strict;
use warnings;
@@ -121,6 +121,28 @@ sub get_mem($) {
return \%mem;
}
+sub get_net($) {
+ my $context = shift;
+ my $dir = get_proc_dir($context) || return undef;
+ my %net = undef;
+
+ open(my $cacct, "<", "$dir/cacct") || return undef;
+ while (<$cacct>) {
+ if ($_ =~ m/^UNIX:\s*[0-9]+/([0-9]+)\s+[0-9]+/([0-9]+)\s+[0-9]+/([0-9]+)\s/) {
+ %net{'unix'} = ($1, $2, $3);
+ }
+ elsif ($_ =~ m/^INET:\s*[0-9]+/([0-9]+)\s+[0-9]+/([0-9]+)\s+[0-9]+/([0-9]+)\s/) {
+ %net{'inet'} = ($1, $2, $3);
+ }
+ elsif ($_ =~ m/^INET6:\s*[0-9]+/([0-9]+)\s+[0-9]+/([0-9]+)\s+[0-9]+/([0-9]+)\s/) {
+ %net{'inet6'} = ($1, $2, $3);
+ }
+ }
+ close($cacct);
+
+ return \%net;
+}
+
1;
__END__
@@ -216,6 +238,31 @@ I<virtual locked memory>
=back
+=item B<get_net($context)>
+
+Return socket information for the vserver specified by the given
+context id. The function reads the B<cacct> file inside the I</proc>
+directory of the vserver and parses the network information. The
+function returns a hashref with an array of recieved, send and
+error bytes for the follwoing values or B<undef> if any error
+occurs:
+
+=over
+
+=item C<unix>
+
+Bytes recieved, send and errored over unix domain sockets.
+
+=item C<inet>
+
+Bytes recieved, send and errored over IPv4 sockets.
+
+=item C<inet6>
+
+Bytes recieved, send and errored over IPv6 sockets.
+
+=back
+
=back
=head1 AUTHORS