Skip to content

Latest commit

 

History

History
89 lines (59 loc) · 2.5 KB

README.textile

File metadata and controls

89 lines (59 loc) · 2.5 KB

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 projects at work.

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.

Installing rails_rrdtool
gem install RailsRRDTool

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.to_i-(60*60*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