I'm in the process of building a 'session browser.'
1. The 'who is online' function basically asks 'who has
fetched a page
in the last N minutes.' The django_session table has an
expire_date
field which can be converted to a sort of 'time of last
click' by
subtracting the 'cookie lifetime' from the expire date to
get 'date of
last session save.' Something like:
dateLastClick = session.expire_date -
datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE)
2. But the session record is only saved (and, hence its
cookie expire
date is only updated) when there is a change in the values
saved in
the session. You can make it more current by setting
"SESSION_SAVE_EVERY_REQUEST = True" in
settings.py. This will add an
additional DB transaction to each page fetch, which is not a
huge deal
for most sites.
3. We also wanted to do full Click Path Analysis. It seemed
silly to
do more database work just to capture information that was
already in
our Apache logs, but we needed a way to tie specific log
entries to a
particular session. Fortunately there is a trivial way to do
this.
Apache comes with a few predefined log formats. Most people
opt for
the 'combined' format, which adds User-agent and Referer to
the
standard info. What I didn't realize (let's hear it for
TFM!) was that
you can put all kinds of stuff in a log entry.
We created a new log format by adding the Django 'sessionid'
cookie to
the end of the log and then redefined the log format:
LogFormat "%h %l %u %t "%r" %>s %b
"%i" "%{User-
agent}i" %C" clickpath
CustomLog logs/www.example.com-access_log clickpath
I don't know how (or if) you can do this on a site where you
can't
modify the server config files.
4. We have two views: one that shows sessions sorted in
various ways
(you can get the session info as a dict by calling
session.get_decoded()), and the other shows a particular
session,
including all of the non-media log entries. We get those
through the
extremely high tech method of grepping for the sessionid in
the log
file. We are still running at fairly low traffic rate (about
6,000
unique sessions per day), but I suspect we will have to
munch the log
into another DB to get decent performance as traffic grows.
HTH,
Peter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|