From 4e8d0d88f6dfa9208c07830112dc97f3f7500bd8 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 12 Feb 2014 04:36:40 +0100 Subject: get_net: add function --- lib/VServer.pm | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) 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 =back +=item B + +Return socket information for the vserver specified by the given +context id. The function reads the B file inside the I +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 if any error +occurs: + +=over + +=item C + +Bytes recieved, send and errored over unix domain sockets. + +=item C + +Bytes recieved, send and errored over IPv4 sockets. + +=item C + +Bytes recieved, send and errored over IPv6 sockets. + +=back + =back =head1 AUTHORS -- cgit v1.2.3-1-g7c22