Example on Graphing Awstats with Ruby and Gruff

30 December, 2006

I spent a moment today testing the Gruff Graphing Library for Ruby to process Awstats data. With the library to handle the graph generated and powerful language, most of the lines of code went to parsing the dataset.

Awstats is a great web statistics software with useful data, and it is even better with graphs like this:

Lifehack.org 2006-Dec Visits by Browsers Graph

By the way, visits by Firefox has exceeded Internet Explorer this month! It’s the first time at lifehack.org.

Example of the awstats dataset
Because the whole file (i.e. awstats122006.www.lifehack.org.txt) is huge, I have stripped the browser section into a separate file. Here is an example of its format.

Source Code
The code is a linear script and I has not tried to polish it, but it serves to show its functionality. The code does the following things:

  • Use hash to store browsers hits
  • Open file and process line by line
  • Use case statements to group browsers hits
  • Create an object of Gruff and pass the hash to g.data()

Leave a Reply

about

Prior to working on Stepcase full-time, Leon Ho was Manager of Software Engineering at Red Hat, responsible for the internationalization deliveries in Red Hat products. Leon managed a team across regions in Australia, Japan, China and India. Leons division added support of 22 languages in Red Hat Enterprise Linux and migrated new internationalization technologies into products. He founded Stepcase's Lifehack in 2005, a blog on productivity and personal development, which became #40 most popular blog in the world. Stepcase has been featured by major medias such as Time Magazine, BusinessWeek and Hong Kong Economic Times.
Find me on LinkedIn, Facebook, and Twitter.

photos

tags

search