Skip to content

talho/rails_rrdtool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is it?

I couldn’t find anything up to date that worked on rails that was paranoid about escaping and protecting the shell so I wrote my own.

I’m actively using this on my project called Servly.

Notes

You can call ‘live’ RRD graphs (ie when a page loads, have an Ajax.Updater load another page that actually graphs the RRd you want)
This works fine under my tests with graphing about 7 RRD’s at the same time.

Todo

Actually write some tests…

Installing rails_rrdtool

cd vendor/plugins && git clone git://github.com/bluescripts/rails_rrdtool.git rails_rrdtool

If you intend on using this in your rails app you need to (or should) put these inside your application_controller.rb file


# path to RRD tool in your environment…. /opt/local/bin is for MAC OSX ports
def rrd_tool
if RAILS_ENV==“development”
return “/opt/local/bin/rrdtool”
else
return “rrdtool”
end
end
# the path to your RRD store (if your app was in /home/app it would go to /home/app/rrd/)
def rrd_path
return Dir.pwd << “/rrd/”
end

# the path to your RRD images
def rrd_image_path
return Dir.pwd << “/public/rrd/”
end

# the web path to your RRD images
def rrd_image_url
if RAILS_ENV==“development”
return “/rrd/”
else
return “/rrd/”
end
end

Creating a RRD

RRD.create(path,params)

example usage:


RRD.create(‘/test.rrd’, {:step => 300, :heartbeat => 600, :ds => [ {:name => “test”, :type => "GAUGE"},
{:name => “josh”, :type => "GAUGE"} ] , :xff => “.5”,
:rra => [ {:type => “max”, :steps => 20, :rows => 1} ] })

first value is a path to the rrd db, the 2nd param is a hash of keys and values

:ds is an array containing hashes for each DataSource (DS) type in the db

:xff is the x files factor (see RRD website for more info on this), range is acceptable between 0 and 1

:rra is a array containing hashes with RRA types and corresponding values

Updating a RRD

RRD.update(path,params)

example usage:

RD.update(‘/test/path.rrd’, [“123”, “456”, 1234])

RRD.update(‘/test/path.rrd’, [“123”, “456a”, 1234])

first param is path to rrd db

2nd param will return data string of 123:456:1234 (each value is sanitized, only numeric values accepted)

to be passed as the data values to be passed to the db

Graphing a RRD

example usage:

RRD.graph(‘/test/path.rrd’,‘/test/path.png’, {:ago => Time.now.advance(:hours => -12), :width => 500, :height => 200, :image_type => “PNG”, :title => “Memory 12hr test”, :defs => [ {:key => “free”, :type => “AVERAGE”, :rpn => “AREA”, :color => “C32227”, :title => “Free Memory” }, {:key => “used”, :type => “AVERAGE”, :rpn => “AREA”, :color => “932D0C”, :title => “Used Memory” } ] , :base => 1024, :vlabel => “gb”, :lowerlimit => 0})

first param is path to rrd

second param is path to store graphed image

third is hash of params

variables for DEF’s are taken care of programatically
Required params
:ago is when to start from, a Time object ( Time.now )
:width, :height
:image_type
:title
:defs => array of hashes

  • [:defs][:key] => The DB data key
  • [:defs][:type] => RRA Type
  • [:defs][:rpn] => RPN Type
  • [:defs][:color] => Hex Color: (accepts: 001122 but not #001122)
  • [:defs][:title] => Title for this DEF
    Optional params
    :base
    :vlabel
    :lowerlimit
    :upperlimit

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 99.4%
  • JavaScript 0.6%