rails_rrdtool – Rails RRDTool Interface
What is it
rails_rrdtool is a Ruby on Rails plugin that provides a ruby-like interface to the RRD program. All variables and hashes sent to the tool are shell escaped so there is no worry about bad input. This is what Servly uses to manipulate RRDs.
Where is it
You can view / download / fork the source over @ GitHub.com
http://github.com/bluescripts/rails_rrdtool/tree/master
How To Install:
script/plugin install git://github.com/bluescripts/rails_rrdtool.git
Put these in your application_controller.rb file and adjust accordingly to your environment:
def rrd_tool if RAILS_ENV=="development" return "/opt/local/bin/rrdtool" else return "rrdtool" end end def rrd_path return Dir.pwd << "/rrd/" end def rrd_image_path return Dir.pwd << "/public/rrd/" end def rrd_image_url if RAILS_ENV=="development" return "/rrd/" else return "/rrd/" end end
How To Use:
Creating a RRD
#this example is taken from Servly # see source for more possibilities of options cpu_hash = {:step => 300, :heartbeat => 600, :ds => [ {:name => "used", :type => "GAUGE"}, {:name => "idle", :type => "GAUGE"} ] , :xff => ".5", :rra => [ {:type => "AVERAGE", :steps => 1, :rows => 10080}, {:type => "MAX", :steps => 60, :rows => 1}, {:type => "MAX", :steps => 180, :rows => 1}, {:type => "MAX", :steps => 360, :rows => 1}, {:type => "MAX", :steps => 720, :rows => 1}, {:type => "MAX", :steps => 1440, :rows => 1}, {:type => "MAX", :steps => 2880, :rows => 1}, {:type => "MAX", :steps => 4320, :rows => 1}, {:type => "MAX", :steps => 10080, :rows => 1} ] } RRD.create("#{rrd_path}file_name.rrd", cpu_hash , "#{rrd_tool}")
Updating a RRD
RRD.update("#{rrd_path}file_name.rrd", [VALUE_1, VALUE_2], "#{rrd_tool}") # as many values as the RRD has
Graphing a RRD
#example from Servly # again see source for all possibilities hash = {:ago => Time.now.advance(:hours => -12), :width => 420, :height => 60, :image_type => "PNG", :title => "CPU 12 Hour", :defs => [ {:key => "used", :type => "AVERAGE", :rpn => "AREA", :color => "2275A0", :title => "CPU Usage" } ], :lowerlimit => 0, :upperlimit => 100, :color => [ {:type => "GRID", :color => "000818"}, {:type => "FONT", :color => "111111"} ] } @cmd = RRD.graph("#{rrd_path}file_name.rrd","#{rrd_image_path}file_name_cpu.png", hash, "#{rrd_tool}")
Apps

Twitter