Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a website hosting a lot of Document files (PDF, XLS, ETC). I frequently get requests for a tally of downloads per month for specific files. Historically, I've just used sed,awk and brethren to grep the apache logs for the desired filename along with entries containing 'GET' and a 200 status code then piping the whole thing to wc.

People are now wanting historical tallies going back through years of logs. Combing through log files takes a lot of time and resources. I'm wondering if there is an apache mod or something similar which will log those GET requests to a database?

share|improve this question
    
and why you don't want to create a simple script bash/php/python (whatever you like) that would parse apache access log (you could run ot via cron every x minutes) and put all necessary information to the database? –  ALex_hha Jul 18 '13 at 14:11
add comment

1 Answer

Do some Click Tracking...and log the clicks you want to a database going forward. For going backwards and collecting from logs, I am no help.

A simple js function for a clicks will log that info.

Include this function on your pages that will post all those requests to a php file:

$('a').bind('click', function() {
      //alert('User clicked on "foo."');
      var e_name = this.name;
      var curr_url = document.URL;
      var to_url = this.href;
      $.ajax({
          type: "POST",
          url: "inc/trackit.php",
          data: { name: e_name, url: curr_url, to_url: to_url, uid: uid }
            }).done(function( msg ) {
          //alert( "Data Saved: " + msg );
        });
    });

The php file that actually posts to the DB could look like this:

<?
include "db_con.php";

$e_name = $_POST['name'];
$curr_url = $_POST['url'];
$to_url = $_POST['to_url'];
$uid = $_POST['uid'];

$track = mysql_query("
        INSERT INTO logs (uid, name, url, to_url, create_date)
        VALUES ('$uid','$e_name','$curr_url','$to_url' ,now())
        ");

?>

Now, so long as all your links have a "name" tag, you will get them logged.

share|improve this answer
    
Neet Idea! I hadn't thought of that. Thanks for the example –  Server Fault Jul 18 '13 at 14:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.