Yoan Blanc’s weblog

Another lost swiss guy

July 2009

Live statistics for your website

Yoan BlancSat 18 July 2009, , ,

If Google Analytics (formerly Urchin) has become one of the most popular tracking systems, it fails at being live because of its architecture. You only get valid data the day after which is the default view anyways. I tried to make something to improve the actual solution we are using at work.

What we do have at work is a basic session counter. It helps us not pushing a release when a lot of people are surfing the website even it has been easier since we switched from Mongrel to Passenger. From a simple number, like “280 sessions” I’d try to move that to the next level and having a view of the actual usage.

The idea is to count views and to store that into memcached using the current time as a key and putting a timeout of the length of the needed graph.

# first visit
memcache.add(now, 1, 3600)

# next visits
memcache.incr(now)

And to build the graph, you get all the values from a set of keys at once and then use Google Chart is used to build a nifty view.

Stats for the last hour (preview)
Stats of the last hour charted by Google Chart.

This is a Rack (or a WSGI) middleware so can fit into your application very easily. Get the source code that contains an example:

  • Ruby (thin -R livestats.ru start)
  • Python (python livestats.py or spawn livestats.application)

Si Google Analytics semble être devenu l’outil de statistiques le plus répandu pour les modestes bourses, il y a un point où il pèche : avoir des données live. C’est dû à l’architecture choisie par Urchin (à l’époque) j’imagine. Architecture qui sert une fonction précise et justement pas celle d’être instantanée.

Le site internet sur lequel je suis employé utilise simplement un compteur du nombre de sessions en cours afin de déterminé si c’est un moment chaud ou normal face à une mise à jour devant être faite. Le but étant bien sûr de minimaliser les coupures. L’idée ici est de donner une information instantanée qui n’est ni pérenne ni représentative du nombre de personnes physiques utilisant le site actuellement. Pour info, ça n’est pas utilisé actuellement, c’était simplement pour mentionné la source d’inspiration et le contexte.

L’idée est de stocker des compteurs dans memcached pour un temps donné et de laisser Google Chart faire le travail de mise en forme.

Le code est à votre disposition :

About

meYoan Blanc is a web developer that lives in Norway (Markveien 24, 0554 Oslo) works for Opera and comes from La Chaux-de-Fonds. This web site is for this weblog, a playground for random stuffs and can help keeping me connected with some friends out there.

Get my vCard or contact me by phone (skype:yoan.blanc) or email ().

Misc

RSS, list.blogug.ch

This site reflects only my opinion and is not affiliated with anyone else.

copyright 2006-2009 — doSimple.ch