[ale] Using access_logs to get counter info

Patman patman at io.com
Fri Jul 28 10:23:58 EDT 2000


Hi all,

I'm pretty much a novice at programming.  I can follow the logic (pretty
much), but the syntax is killing me.  Here's what a friend of mine came up
with for the logic: 

---

Use three files, "tempfile", "weeklyfile", and "totalfile"

Count in log and write to "tempfile".

Compare "tempfile" to "weeklyfile".

if "tempfile" less than "weeklyfile", sum "weeklyfile" and "totalfile",
then reset "weeklyfile" to "tempfile"

(If I'm thinking right, the only time "tempfile" should be less than
"weeklyfile" is when the log has been cleared... so it would total once a
week unless there were no accesses for the week.)

if "tempfile" greater than "weeklyfile", reset "weeklyfile" to "tempfile".

So, if I did that right, you would only update "weeklyfile" when the
result of your grep was greater than your current count.  When the logs
clear, you add that weekly total into an overall total.

Then print the total on the page when you have it execute this perl
script. 
---

So I was wondering is someone would be able to provide some dummy perl 
code to implement the logic from above.  I think that would work without
relying on changing any cron entries. 

I envision this script would run on each page access to the page. 

TIA. 

 On Fri, 28 Jul 2000, Wandered Inn wrote:
> 
> You could get rid of grep and use perl for all of this.
> 
> How is the counter updated?  Via cron?  Via a web page?  Point is, all
> you would have to do is when you read the value in, sum that with the
> new log value, and update your file that contains your counter. You
> could make this a part of your log rotation process.
> 
> Patman wrote:
> > 
> > Hi,
> > 
> > Thanks for the grep help, just want I was looking for.  Here's my next
> > problem which I was hoping someone might give me some pointers in setting
> > up a photo hits counter:
> > 
> > So is there a perl guru in the house?  I really need help in keeping track
> > of photo hits on my pages.  This is a little different than just having a
> > counter on a page that gets bumped up per page access (since loading the
> > page will execute the counter script).
> > 
> > I have successfully written a very short perl script to do the counting
> > for the photo hits. I'm using my var/httpd/log/access_log to 'grep' and
> > count each instance a file from a specific directory gets accessed in
> > order to get the count of hits, and I pipe that number to a file, and then
> > I open the file and get the number, close the file, and print the number
> > as the hit count.  This photo hit counter only gets updated on each page
> > access.
> > 
> > But since these are access_logs, they get gets reset to zero every week,
> > and so does my counter too.  I have no idea how to add one week's count
> > numbers to another counter which is the cumulative total of the past
> > weeks' photo hits, and then and get it to print on my webpage.  Any ideas?
> > 
> > Is there a way to pipe the last week's final hit total to another counter
> > text file before the access_log gets reset to zero (my web setup will keep
> > the last 4 week's of access_logs), and have it as a cumulative total of
> > all the previous week's worth of hits?
> > 
> > TIA.
> > 
> > On Thu, 27 Jul 2000, Wandered Inn wrote:
> > 
> > > Date: Thu, 27 Jul 2000 12:39:08 -0400
> > > From: Wandered Inn <esoteric at denali.atlnet.com>
> > > To: Atlanta Linux Enthusiasts <ale at ale.org>
> > > Subject: Re: [ale] Using access_logs to get counter info
> > >
> > > Save the '|' and a process, use 'grep -c'
> > >
> > > grep -c "images/patman.gif" /var/log/httpd/access_log
> > >
> > > Gary Maltzen wrote:
> > > >
> > > > To count the number of lines containing the phrase "images/patman.gif":
> > > >
> > > >   grep "images/patman.gif" /var/log/httpd/access_log | wc -l
> > > >
> > > > To do this for all access logs (without compressed logs)
> > > >
> > > >   grep "images/patman.gif" /var/log/httpd/access_log* | wc -l
> > > >
> > > > To do this for all access logs (compressed logs)
> > > >
> > > >   (grep "images/patman.gif" /var/log/httpd/access_log & \
> > > >   zgrep "images/patman.gif" /var/log/httpd/access_log*gz) | \
> > > >   wc -l
> > > >
> > > > > I am running Apache 1.3.9 on Redhat 6.1, and wanted to use my access_logs
> > > > > to keep a count of how many times certain files in specific directories
> > > > > show up as being accessed in the access_logs.  I have a few webpages with
> > > > > lots of photos on them, and would like to find a way to see how many hits
> > > > > I get for each page of photos (which are sorted and placed in different
> > > > > directories per page).
> > > > >
> > > > > I would like to key off the directory name, and how many times a
> > > > > directory name shows up as being accessed from the access_logs.  This
> > > > > would give me the hit info I want.  I already have a counter that counts
> > > > > just the number of page accesses per page on each page, but this isn't
> > > > > feasible on a per-photo-file basis.  Once I get this "number of hits" per
> > > > > directory according to the access_logs, I'd like to display number on each
> > > > > page too.
> > > >
> > > > --
> > > > To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
> > >
> > > --
> > > Until later: Geoffrey         esoteric at denali.atlnet.com
> > >
> > > Microsoft != Innovation
> > > --
> > > To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
> > >
> > 
> > --
> > To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
> 
> --
> Until later: Geoffrey		esoteric at denali.atlnet.com
> 
> Microsoft != Innovation
> --
> To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
> 

--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list