Database Reference
In-Depth Information
Then restart Apache to enable the new logging directives. After your web server receives
a few requests, take a look at the test_log file. Verify that the contents are as you expect,
then feed the file to httpdlog.pl :
% /usr/local/apache/bin/httpdlog.pl test_log
After httpdlog.pl finishes, take a look at the httpdlog table to make sure that it looks
correct. Once you're satisfied, tell Apache to send log entries directly to httpdlog.pl by
modifying the CustomLog directive as follows:
CustomLog "|/usr/local/apache/bin/httpdlog.pl" mysql
The | character at the beginning of the pathname tells Apache that httpdlog.pl is a
program, not a file. Restart Apache and new entries should appear in the httpdlog table
as visitors request pages from your site.
Nothing you have done to this point changes any logging you may have been doing
originally. For example, if you were logging to an access_log file before, you still are now,
so Apache is sending entries both to the original logfile and to MySQL. If that's what
you want, fine. Apache doesn't care if you log to multiple destinations, but you'll use
more disk space. To disable file logging, disable your original CustomLog directive and
restart Apache.
Analyzing the logfile
Now that Apache is logging into the database, what you do with the information depends
on what you want to know. Here are some questions MySQL can answer easily:
• How many requests were received?
SELECT COUNT ( * ) FROM httpdlog ;
• How many different client hosts sent requests?
SELECT COUNT ( DISTINCT host ) FROM httpdlog ;
• How many different pages did clients request?
SELECT COUNT ( DISTINCT url ) FROM httpdlog ;
• What are the 10 most popular pages?
SELECT url , COUNT ( * ) AS count FROM httpdlog
GROUP BY url ORDER BY count DESC LIMIT 10 ;
• How many requests were received for favicon.ico files that certain browsers like to
check for?
SELECT COUNT ( * ) FROM httpdlog WHERE url LIKE '%/favicon.ico%' ;
• What is the range of dates spanned by the log?
SELECT MIN ( dt ), MAX ( dt ) FROM httpdlog ;
• How many requests were received each day?
Search WWH ::




Custom Search