<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Check how much web bandwidth your users are using</title>
	<atom:link href="http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/</link>
	<description></description>
	<pubDate>Wed, 19 Nov 2008 11:39:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: volksman</title>
		<link>http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-64</link>
		<dc:creator>volksman</dc:creator>
		<pubDate>Wed, 16 Apr 2008 12:08:34 +0000</pubDate>
		<guid isPermaLink="false">http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-64</guid>
		<description>Thanks!!!</description>
		<content:encoded><![CDATA[<p>Thanks!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Timucin Kizilay</title>
		<link>http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-62</link>
		<dc:creator>Timucin Kizilay</dc:creator>
		<pubDate>Wed, 16 Apr 2008 06:01:58 +0000</pubDate>
		<guid isPermaLink="false">http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-62</guid>
		<description>Thank you Jacom, and thank you Nick.
I was looking for a script like this for my server. I do not know Perl so I'll try the Python version. 
Now I have another question for you. My log files are in /var/log/apache2/site/ directory. the log files in /var/log are being rotated daily by the system but the apache logs are growing all the time. How can I rotate them automatically like the log files in /var/log ? My server is an ubuntu server edition 7.10.</description>
		<content:encoded><![CDATA[<p>Thank you Jacom, and thank you Nick.<br />
I was looking for a script like this for my server. I do not know Perl so I&#8217;ll try the Python version.<br />
Now I have another question for you. My log files are in /var/log/apache2/site/ directory. the log files in /var/log are being rotated daily by the system but the apache logs are growing all the time. How can I rotate them automatically like the log files in /var/log ? My server is an ubuntu server edition 7.10.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Presta</title>
		<link>http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-60</link>
		<dc:creator>Nick Presta</dc:creator>
		<pubDate>Wed, 16 Apr 2008 03:11:42 +0000</pubDate>
		<guid isPermaLink="false">http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-60</guid>
		<description>Great little tool.

I thought it would be a good exercise to do something like this in Python, so here it goes:
http://nickpresta.ath.cx/lab/python/bwlog

It doesn't handle rotating logs like yours does, but its simple enough for me.</description>
		<content:encoded><![CDATA[<p>Great little tool.</p>
<p>I thought it would be a good exercise to do something like this in Python, so here it goes:<br />
<a href="http://nickpresta.ath.cx/lab/python/bwlog" rel="nofollow">http://nickpresta.ath.cx/lab/python/bwlog</a></p>
<p>It doesn&#8217;t handle rotating logs like yours does, but its simple enough for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rhesa</title>
		<link>http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-57</link>
		<dc:creator>rhesa</dc:creator>
		<pubDate>Tue, 15 Apr 2008 22:44:07 +0000</pubDate>
		<guid isPermaLink="false">http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-57</guid>
		<description>Here's an even terser solution (skipping the stuff around the loop):


    @ARGV = glob("/home/${cuser}.logs/*.access.log*" );
    while() {
    # split etc
    }


That's a useful idiom, which I keep forgetting myself ;-)</description>
		<content:encoded><![CDATA[<p>Here&#8217;s an even terser solution (skipping the stuff around the loop):</p>
<p>    @ARGV = glob(&#8221;/home/${cuser}.logs/*.access.log*&#8221; );<br />
    while() {<br />
    # split etc<br />
    }</p>
<p>That&#8217;s a useful idiom, which I keep forgetting myself <img src='http://jacob.peddicord.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rhesa</title>
		<link>http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-55</link>
		<dc:creator>rhesa</dc:creator>
		<pubDate>Tue, 15 Apr 2008 20:16:53 +0000</pubDate>
		<guid isPermaLink="false">http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-55</guid>
		<description>Hmm, sorry about that. How do you do code on this blog?

Anyway, the while() should read while(&#60;$fh&#62;)...</description>
		<content:encoded><![CDATA[<p>Hmm, sorry about that. How do you do code on this blog?</p>
<p>Anyway, the while() should read while(&lt;$fh&gt;)&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rhesa</title>
		<link>http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-54</link>
		<dc:creator>rhesa</dc:creator>
		<pubDate>Tue, 15 Apr 2008 20:14:50 +0000</pubDate>
		<guid isPermaLink="false">http://jacob.peddicord.net/blog/2008/04/15/check-how-much-web-bandwidth-your-users-are-using/#comment-54</guid>
		<description>It's pretty inefficient to first copy all the logs in a directory to a file in /tmp, and then to slurp that entire file into memory.

Let me try improving that a bit (and I do hope code remains intact):

&lt;code&gt;#!/usr/bin/perl -w

my $month = shift
    or die "Usage: ckbw month\nPrints the bandwidth used in a month.\nUse shorthand notation (ie, Jan, Feb, Mar)\n";

my $cuser = $ENV{"USER"};
my $total = 0;

#find all of the log files for the user
for my $logfile ( glob( "/home/"${cuser}.logs/*.access.log*" ) ) {
    open my $fh, $logfile or do {
        warn "couldn't open $logfile: $! (skipping)";
        next; 
    };

    while(&lt;$fh&gt;) {
        my @linesep = split / /;

        #check the month
        if($linesep[3] =~ m/$month/i) {
            #make sure there is an actual value
            if($linesep[9] =~ m/\d/) {
                $total += $linesep[9];
            }
        }
    }
}

print "Bandwidth totals:\n";
print $total." bytes\n";
$total /= 1024;
print $total." KB\n";
$total /= 1024;
print $total." MB\n";
$total /= 1024;
print $total." GB\n";&lt;/code&gt; &lt;em&gt;[fixed formatting -Jacob]&lt;/em&gt;</description>
		<content:encoded><![CDATA[<p>It&#8217;s pretty inefficient to first copy all the logs in a directory to a file in /tmp, and then to slurp that entire file into memory.</p>
<p>Let me try improving that a bit (and I do hope code remains intact):</p>
<p><code>#!/usr/bin/perl -w</p>
<p>my $month = shift<br />
    or die "Usage: ckbw month\nPrints the bandwidth used in a month.\nUse shorthand notation (ie, Jan, Feb, Mar)\n";</p>
<p>my $cuser = $ENV{"USER"};<br />
my $total = 0;</p>
<p>#find all of the log files for the user<br />
for my $logfile ( glob( "/home/"${cuser}.logs/*.access.log*" ) ) {<br />
    open my $fh, $logfile or do {<br />
        warn "couldn't open $logfile: $! (skipping)";<br />
        next;<br />
    };</p>
<p>    while(< $fh>) {<br />
        my @linesep = split / /;</p>
<p>        #check the month<br />
        if($linesep[3] =~ m/$month/i) {<br />
            #make sure there is an actual value<br />
            if($linesep[9] =~ m/\d/) {<br />
                $total += $linesep[9];<br />
            }<br />
        }<br />
    }<br />
}</p>
<p>print &#8220;Bandwidth totals:\n&#8221;;<br />
print $total.&#8221; bytes\n&#8221;;<br />
$total /= 1024;<br />
print $total.&#8221; KB\n&#8221;;<br />
$total /= 1024;<br />
print $total.&#8221; MB\n&#8221;;<br />
$total /= 1024;<br />
print $total.&#8221; GB\n&#8221;;</code> <em>[fixed formatting -Jacob]</em></p>
]]></content:encoded>
	</item>
</channel>
</rss>
