Slidingstats


Sliding Stats

Sliding Stats is a small little piece of code I'm working on to plug into any Rack enabled Ruby web app (and practically any Ruby web-framework can work with Rack these days) to give me glimpse of what's going on without having to tail referrer logs etc.

It doesn't do all that much, and I don't want it to: It keeps a "sliding window" of requests that doesn't match a list of criteria for things you want to ignore, and maintains a graph of referrers, pages, and referrers broken down by pages (the latter as a table). When the limit is hit, old requests are removed, so if you set the limit for the window low enough, you'll see a constantly changing view of where people are clicking through to your site from, and to what pages.

For an example of what it looks like, see my stats page

Since it ties in with Rack you can use this regardless of what web framework you use, as long as it has a Rack adapter. That means Rails, Merb, Sinatra, Camping and bunch of others.

The code is on GitHub. Please note that I've just pushed this out, so don't try it out on any sites you worry about actually keeping running - I'm sure there are nasty bugs in there. Comments / suggestions welcome...

I don't plan on adding all that many enhancements to it - for "proper stats" I use Google Analytics - but I will tweak things like the filtering of requests, and I want to add an option to make the limit time based instead of just by number of queries. I'll probably clean up the CSS a bit too, and pretty up the SVG graphs.

Watch the Github repository if you want to see what I'm up to, or keep an eye on my blog

Installation

To install it you'll need SVG::Graph installed - unfortunately I don't think there's any gems for that available.

Then you can download sliding-stats-0.2.5.gem and install it.

Configuration

More documentation is forthcoming, but for now, to include it in your Rack setup, adapt this example and add it to your config.ru file:

require 'sliding-stats'

use SlidingStats::Window,{
  :limit => 1000,
  :persist => 10,
  :ignore => [
    /\/robots.txt/,
    /http:\/\/search.live.com\/results.aspx/, # MSN referer spam (also real searches, but the spam far outweighs the real users)     
    /\.xml/, /\/feed/, /\.rdf/, /\.ico/,
    /\/static\/images.*/,/\.css/,/\.js/,/\.png/,/\.svg/,/\.jpg/,
    /\/stats/
  ],
  :exclude_referers => [
    /^-/
  ],
  :exclude_pages => [ # Pages that are not ignored, but that I don't want to see in the pages graph (but do want to see referrers fo\
r)                                                                                                                                   
  ],
  :rewrite_referers =>
    [
    [/http:\/\/.*\.google\..*?[?&]q=([^&]*)?&*.*/,"Google Search: '\\1'"],
    [/http:\/\/.*\.ask\..*?[?&]q=([^&]*)?&*.*/,"Ask.com Search: '\\1'"],
    [/http:\/\/www.google..*\/reader.*/,"Google Reader"]
    ]
}

use SlidingStats::Controller, {:base => "/stats", :max_entries => 100}


Articles tagged 'slidingstats'

2009-02-19
Sliding Stats: Rack Middleware to keep an eye on your traffic

Sliding Stats is a small little piece of code I'm working on to plug into any Rack enabled Ruby web app (and practically any Ruby web-framework can work with Rack these days) to give me glimpse of what's going on without having to tail referrer logs etc.
It doesn't do ...