tags:

views:

446

answers:

4

It's surprising how difficult it is to find a simple, concise answer to this question:

  1. I have a file, foo.zip, on my website
  2. What can I do to find out how many people have accessed this file?
  3. I could use Tomcat calls if necessary

Update: If you suggest writing a script, can you point me to a decent one?

+6  A: 

The simplest way would probably be instead of linking directly to the file, link to a script which increments a counter and then forwards to the file in question.

mrhahn
A: 

Use the logs--each GET request for the file is another download (unless the visitor stopped the download partway through for some reason).

Max
+5  A: 

Or you could parse the log file if you don't need the data in realtime.

cat /path/to/access.log | grep foo.zip | grep 200 | wc -l

In reply to comment:

The log file also contains bytes downloaded, but as someone else pointed out, this may not reflect the correct count if a user cancels the download on the client side.

Sean Bright
definitely simplest if you have access to the logs
Mark Baker
does this tell you if the download was completed or cancelled?
Steven A. Lowe
A: 

the download of a file is done on the client side in a separate thread, which the user can cancel, so there does not appear to be a reliable way to count 'full' downloads, only download attempts

Steven A. Lowe