diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VServer.pm | 49 |
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 |