Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

Monitoring users bandwidth

12 like 0 dislike
Can people think of an effective way to monitor a users bandwidth?

I am running a site where a user will have a blog type site on a subdomain.

for example.

kalyse.domain.com

All this is an A DNS Record with a wildcard that forwards to a single script on a server. Theres no actual subdomaining involved.
The problem is I need to count the bandwidth a user uses for anything from their 'domain'. This includes any downloads or what not.

I cant really think of a way except log trawling... but surely this is going to be one pain in the ass. How do software panels do this effectively?
asked 3 months ago by webmaster (25,330 points)

2 Answers

1 like 0 dislike
 
Best answer
Is how I would do it with a cpanel server, that prolly won't work for you, you will need to match something else in the logs to identify where the traffic is going, but still that's how you would do it, load the log file into an array loop over each line matching the request location and status and numbers and then write some if clauses to collect the correct data from the matched data.

If you don't have access to cpanel, or still don't get it, then please take about 20 lines out of the log file you want to parse and post it, and tell me what is identifying each seperate "subdomain"

PHP Code:

<?
function cpanel_logs( $username, $password, $domain, $searchpath )
{
    $bw = 0 ;
    $logs = file( sprintf(  'http://%s:%s@%s:2082/getlogarchive/%s',
                            $username,
                            $password,
                            $domain,
                            $domain ));
    if( $logs )
    {
        foreach( $logs as $line )
        {
            preg_match( '~"([A-Z]+) (.*?[^ ]) HTTP/1\.[1|0]" ([0-9]+) ([0-9]+) "(.*?[^"])" "(.*?[^"])"~si',
                        $line,
                        $matches
            );
           
            if( ereg( $searchpath, $matches[2] ) )
            {
                $bw += $matches[4];    
            }
        }
    }
   
    return $bw ;
}

$username = 'username';
$password = 'password';
$hostname = 'hostname.com';

printf( 'Images on %s have taken up a total of %01.2fMB bandwidth today<br />',
        $hostname,
        cpanel_logs( $username, $password, $hostname, 'images' ) / 1048576
);
       
printf( '%s has taken up a total of %01.2fMB bandwidth today<br />',
        $hostname,
        cpanel_logs( $username, $password, $hostname, '/' ) / 1048576
);
?>
answered 3 months ago by monirulislam (51,500 points)
thnx monirulislam, i've been lookin for it from somedays.
3 months ago by joro (8,470 points)
0 like 0 dislike
Bandwidth Monitoring tools can easily identifies which users, applications, and protocols are consuming the most network bandwidth and highlights the IP addresses of the top talkers on the network.
Available at http://www.solarwinds.com
answered 1 month ago by Prabhdeep (300 points) edited 4 weeks ago by Prabhdeep

Related questions

5 like 0 dislike
1 answer
6 like 0 dislike
1 answer
asked 3 months ago by digita-book.com (9,700 points)
8 like 0 dislike
0 answers
asked 3 months ago by lotus$ (41,950 points)
7 like 0 dislike
0 answers
asked 3 months ago by marck_don (190,990 points)
1 like 0 dislike
0 answers