Object
TODO: add bang methods
# File lib/rrd/base.rb, line 106 def bang(method, *args, &block) result = send(method, *args, &block) raise error unless result result end
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
# 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
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
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
# File lib/rrd/base.rb, line 60 def last_update Wrapper.last_update(rrd_file) end
# File lib/rrd/base.rb, line 102 def methods super + BANG_METHODS end
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
# 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
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
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
Generated with the Darkfish Rdoc Generator 2.