In Files

Parent

RRD::Base

TODO: add bang methods

Attributes

rrd_file[RW]

Public Class Methods

new(rrd_file) click to toggle source
# File lib/rrd/base.rb, line 11
def initialize(rrd_file)
  @rrd_file = rrd_file
end

Public Instance Methods

bang(method, *args, &block) click to toggle source
# File lib/rrd/base.rb, line 106
def bang(method, *args, &block)
  result = send(method, *args, &block)
  raise error unless result
  result
end
create(options = {}, &block) click to toggle source

Creates a rrd file. Basic usage:

rrd.create :start => Time.now - 10.seconds, :step => 5.minutes do
  datasource "memory", :type => :gauge, :heartbeat => 10.minutes, :min => 0, :max => :unlimited
  archive :average, :every => 10.minutes, :during => 1.year
end
# File lib/rrd/base.rb, line 24
def create(options = {}, &block)
  builder = RRD::Builder.new(rrd_file, options)
  builder.instance_eval(&block)
  builder.save
end
dump(xml_file, options = {}) click to toggle source
# File lib/rrd/base.rb, line 30
def dump(xml_file, options = {})
  options = options.clone
  line_params = RRD.to_line_parameters(options, DUMP_FLAGS)
  Wrapper.dump(rrd_file, xml_file, *line_params)
end
ends_at() click to toggle source

Returns a time object with the last entered value date

# File lib/rrd/base.rb, line 37
def ends_at
  Time.at Wrapper.last(rrd_file)
end
Also aliased as: last
error() click to toggle source
# File lib/rrd/base.rb, line 15
def error
  Wrapper.error
end
fetch(consolidation_function, options = {}) click to toggle source

Basic usage: rrd.fetch :average

# File lib/rrd/base.rb, line 44
def fetch(consolidation_function, options = {})
  options = {:start => Time.now - 1.day, :end => Time.now}.merge options
  
  options[:start] = options[:start].to_i
  options[:end] = options[:end].to_i
  line_params = RRD.to_line_parameters(options)
  
  Wrapper.fetch(rrd_file, consolidation_function.to_s.upcase, *line_params)
end
first() click to toggle source
Alias for: starts_at
info() click to toggle source

See RRD::Wrapper.info

# File lib/rrd/base.rb, line 55
def info
  Wrapper.info(rrd_file)
end
last() click to toggle source
Alias for: ends_at
last_update() click to toggle source

See RRD::Wrapper.last_update

# File lib/rrd/base.rb, line 60
def last_update
  Wrapper.last_update(rrd_file)
end
methods() click to toggle source
# File lib/rrd/base.rb, line 102
def methods
  super + BANG_METHODS
end
resize(rra_num, options) click to toggle source

Writes a new file ‘resize.rrd’

You will need to know the RRA number, starting from 0:

rrd.resize(0, :grow => 10.days)
# File lib/rrd/base.rb, line 69
def resize(rra_num, options)
  info = self.info
  step = info["step"]
  rra_step = info["rra[#{rra_num}].pdp_per_row"]
  action = options.keys.first.to_s.upcase
  delta = (options.values.first / (step * rra_step)).to_i # Force an integer
  Wrapper.resize(rrd_file, rra_num.to_s, action, delta.to_s)
end
restore(xml_file, options = {}) click to toggle source

See RRD::Wrapper.restore

# File lib/rrd/base.rb, line 79
def restore(xml_file, options = {})
  options = options.clone
  line_params = RRD.to_line_parameters(options, RESTORE_FLAGS)
  Wrapper.restore(xml_file, rrd_file, *line_params)
end
starts_at() click to toggle source

Returns a time object with the first entered value date

# File lib/rrd/base.rb, line 86
def starts_at
  Time.at Wrapper.first(rrd_file)
end
Also aliased as: first
update(time, *data) click to toggle source

Basic usage: rrd.update Time.now, 20.0, 20, nil, 2

Note: All datasources must receive a value, based on datasources order in rrd file

# File lib/rrd/base.rb, line 94
def update(time, *data)
  new_data = data.map {|item| item.nil? ? "U" : item}
  new_data = [time.to_i] + new_data
  
  Wrapper.update(rrd_file, new_data.join(":"))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.