Rifgraf

rifgraf opensource

Tue Sep 16 11:38:00 -0700 2008

Ever want to store some metrics from an app, and later graph the results? I often do. Stuff like: number of users, number of daily orders, or number of tickets closed per week.

And how do you implement this? Create a table or three in your app’s database, a cron job that populates the table, and a page somewhere in your admin interface that draws a graph with something like Gruff? Yeah, me too - and it sucks.

Mingling metrics into your app’s database is as bad as putting business logic into your view. Not to mention that the data tends to get big over time, weighing down your main database.

Well, I got sick of that. So I made Rifgraf.

Rifgraf is a fire-and-forget web service for displaying graphs of data collected over time. Post your data points periodically via rest calls. Then view a graph of the data at any time in the future.

Let’s try it!

1. Post some data points.

You’ll probably do this from a cron job, but try it from an irb session first.

RestClient.post 'http://rifgraf.heroku.com/graphs/sample', :value => rand(99)

Or for the Ruby-impaired, from the shell:

$ curl http://rifgraf.heroku.com/graphs/sample -X POST -d value=$RANDOM

eplace “sample” with whatever graph name you want. This is the graph key.

2. Visit your graph.

http://rifgraf.heroku.com/graphs/sample

Replace “sample” with your chosen key. You’re catching on, right?

3. Bask in the glory of the zoomable graph.

…with no clutter in your app’s main database.

Rifgraf automatically timestamps data that you post, although you can include a :timestamp parameter if you want to use a different one. i.e.

RestClient.post 'http://rifgraf.heroku.com/graphs/sample', :value => 42, :timestamp => '1999-31-12'

Clear your all data from a graph and start fresh - the “how” won’t be surprising to restafarians:

RestClient.delete 'http://rifgraf.heroku.com/graphs/sample'

What kind of protection is there from other people viewing your graph, posting their own data, or clearing your existing data? None at all. Rifgraf has no logins, inspired by this. Consider whether your data is really so valuable that an obfuscated graph name isn’t enough protection for it. (Hint: it probably isn’t.) If it is, or if you want to make your own customizations, grab the source code and host your own private Rifgraf.

If you make interesting changes, send me a pull request. Making the graphs prettier (like a dark background and thicker lines) would be a good start. Docs for the graph settings are here.