The basic architecture of this (very simple) metrics gathering and display application is:
- Scripts run as crons from within the rails directory. Every minute, the cron wakes up and checks the database for the last time run and the poll interval. If they are
- They update RRD files and generate .pngs that reside in the rails /public dir.
- they update the latest value, and the last time run.
The scripts and the rails app intersect at two points:
- the interval and last time polled
- the generated PNG file.
I may choose to store and display the last collected value, but that will happen after getting feedback from my customers (the development, operations, and product teams).
Since the script has to check the interval and the last time polled, it needs access to the database. I naturally wanted to use the ActiveRecord classes that I use in the rails app, I also wanted access to rails environment variables, like RAILS_ROOT.
By requiring environment.rb:
require File.dirname(__FILE__) + '/../../config/environment.rb'
I was able to get rails like behavior into my scripts.