Apache-Bwlog

 view release on metacpan or  search on metacpan

Bwlog.pm  view on Meta::CPAN


sub db_connect
{
	my $r = shift;
	my $Bwlog_mysql_database = $r->dir_config("Bwlog_mysql_database");
	my $Bwlog_mysql_server = $r->dir_config("Bwlog_mysql_server");
	my $Bwlog_mysql_user = $r->dir_config("Bwlog_mysql_user");
	my $Bwlog_mysql_password = $r->dir_config("Bwlog_mysql_password");
	
	return DBI->connect("DBI:mysql:$Bwlog_mysql_database:$Bwlog_mysql_server", $Bwlog_mysql_user, $Bwlog_mysql_password);
}

sub read_shm_hash
{
	## Since the sharelite module doesn't support var types, we are going to store a structure to read/write our hash back and forth.
	my $sem_data = $share_sem->fetch();
	my @conv_array = split(/&/, $sem_data);
	my $inc = 0;
	my ($k, $v);
	while($conv_array[$inc])
	{
		($k, $v) = split(/=/, $conv_array[$inc]);
		$shared_hash{ "$k" } = $v;
		$inc++;
	}
}	
sub write_shm_hash
{
	my($k, $v) = each(%shared_hash);
	my $shm_buffer;
	while($k)
	{
		$shm_buffer = $shm_buffer . "$k=$v&";
		($k, $v) = each(%shared_hash);
	}
	$share_sem->store("$shm_buffer");
}
	
	
	
# Preloaded methods go here.

1;
__END__


=head1 Apache::Bwlog

Apache::Bwlog - Vhost bandwidth logger for mod_perl.

=head1 SYNOPSIS

  Place this in the httpd.conf file :
  
  PerlLogHandler Apache::Bwlog

  Apache Directives
  
=item *  PerlSetVar Bwlog active
  
  	This value is required if plan to use the module at all.  This can be placed globally
	to effect all virtual hosts on the machine, or in a single VirtualHost context which 
	only activates logging for that host
	
  
=item *  PerlSetVar Bwlog_threshold <bytes>
  
  	Set the "bitbucket" maximum before purging the current counter.  Be aware that setting
	this value to low can add a lot of disk I/O, and or CPU time.  For a high volume site 
	a large number is recommended here.  Defaults to 100,000 bytes.
	
=item *  PerlSetVar Bwlog_logtype <type>
  	
  	Valid types are currently "file" and "mysql".  The mysql portion requires the directives
	described below.
  
=item * PerlSetVar Bwlog_mysql_user

=item * PerlSetVar Bwlog_mysql_password

=item * PerlSetVar Bwlog_mysql_server

=item * PerlSetVar Bwlog_mysql_database

=item * PerlSetVar Bwlog_mysql_tablename
  


=item * PerlSetVar Bwlog_logdir <directory>

	Resets the value for where your vhost bwlogs are stored if the file option is chosen. 
	This option defaults to : /usr/local/apache/logs

=head1 Table Create Syntax For mysql driver

	The following create will work for the mysql database :
	
	CREATE TABLE `bw_log` (
	  `bw_id` bigint(20) NOT NULL auto_increment,
	  `vhost` varchar(100) NOT NULL default '',
	  `bytes_sent` bigint(20) NOT NULL default '0',
	  `time_stamp` timestamp(14) NOT NULL,
	  PRIMARY KEY (`bw_id`)
	) 	
	
	
	
=head1 ABSTRACT

	httpd.conf Example.

	PerlLogHandler Apache::Bwlog

	PerlSetVar Bwlog_mysql_user bw_user
	PerlSetVar Bwlog_mysql_password bw_password
	PerlSetVar Bwlog_mysql_server 127.0.0.1
	PerlSetVar Bwlog_mysql_database bw_logger
	PerlSetVar Bwlog_mysql_tablename bw_log
	
	PerlSetVar Bwlog active
	PerlSetVar Bwlog_threshold 100000



( run in 2.261 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )