Class: RRD::Base
- Inherits:
-
Object
- Object
- RRD::Base
- Defined in:
- lib/rrd/base.rb
Overview
TODO: add bang methods
Constant Summary collapse
- BANG_METHODS =
[:create!, :dump!, :ends_at!, :fetch!, :first!, :info!, :last!, :last_update!, :resize!, :restore!, :starts_at!, :update!]
- RESTORE_FLAGS =
[:force_overwrite, :range_check]
- DUMP_FLAGS =
[:no_header]
Instance Attribute Summary collapse
-
#rrd_file ⇒ Object
Returns the value of attribute rrd_file.
Instance Method Summary collapse
- #bang(method, *args, &block) ⇒ Object
-
#create(options = {}, &block) ⇒ Object
Creates a rrd file.
- #dump(xml_file, options = {}) ⇒ Object
-
#ends_at ⇒ Object
(also: #last)
Returns a time object with the last entered value date.
- #error ⇒ Object
-
#fetch(consolidation_function, options = {}) ⇒ Object
Basic usage: rrd.fetch :average.
-
#info ⇒ Object
See RRD::Wrapper.info.
-
#initialize(rrd_file) ⇒ Base
constructor
A new instance of Base.
-
#last_update ⇒ Object
See RRD::Wrapper.last_update.
- #methods ⇒ Object
-
#resize(rra_num, options) ⇒ Object
Writes a new file ‘resize.rrd’.
-
#restore(xml_file, options = {}) ⇒ Object
See RRD::Wrapper.restore.
-
#starts_at ⇒ Object
(also: #first)
Returns a time object with the first entered value date.
-
#update(time, *data) ⇒ Object
Basic usage: rrd.update Time.now, 20.0, 20, nil, 2.
Constructor Details
#initialize(rrd_file) ⇒ Base
Returns a new instance of Base.
12 13 14 |
# File 'lib/rrd/base.rb', line 12 def initialize(rrd_file) @rrd_file = rrd_file end |
Instance Attribute Details
#rrd_file ⇒ Object
Returns the value of attribute rrd_file.
5 6 7 |
# File 'lib/rrd/base.rb', line 5 def rrd_file @rrd_file end |
Instance Method Details
#bang(method, *args, &block) ⇒ Object
107 108 109 110 111 |
# File 'lib/rrd/base.rb', line 107 def bang(method, *args, &block) result = send(method, *args, &block) raise error unless result result end |
#create(options = {}, &block) ⇒ Object
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
25 26 27 28 29 |
# File 'lib/rrd/base.rb', line 25 def create( = {}, &block) builder = RRD::Builder.new(rrd_file, ) builder.instance_eval(&block) builder.save end |
#dump(xml_file, options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/rrd/base.rb', line 31 def dump(xml_file, = {}) = .clone line_params = RRD.to_line_parameters(, DUMP_FLAGS) Wrapper.dump(rrd_file, xml_file, *line_params) end |
#ends_at ⇒ Object Also known as: last
Returns a time object with the last entered value date
38 39 40 |
# File 'lib/rrd/base.rb', line 38 def ends_at Time.at Wrapper.last(rrd_file) end |
#error ⇒ Object
16 17 18 |
# File 'lib/rrd/base.rb', line 16 def error Wrapper.error end |
#fetch(consolidation_function, options = {}) ⇒ Object
Basic usage: rrd.fetch :average
45 46 47 48 49 50 51 52 53 |
# File 'lib/rrd/base.rb', line 45 def fetch(consolidation_function, = {}) = {:start => Time.now - 1.day, :end => Time.now}.merge [:start] = [:start].to_i [:end] = [:end].to_i line_params = RRD.to_line_parameters() Wrapper.fetch(rrd_file, consolidation_function.to_s.upcase, *line_params) end |
#info ⇒ Object
See RRD::Wrapper.info
56 57 58 |
# File 'lib/rrd/base.rb', line 56 def info Wrapper.info(rrd_file) end |
#last_update ⇒ Object
See RRD::Wrapper.last_update
61 62 63 |
# File 'lib/rrd/base.rb', line 61 def last_update Wrapper.last_update(rrd_file) end |
#methods ⇒ Object
103 104 105 |
# File 'lib/rrd/base.rb', line 103 def methods super + BANG_METHODS end |
#resize(rra_num, options) ⇒ Object
Writes a new file ‘resize.rrd’
You will need to know the RRA number, starting from 0:
rrd.resize(0, :grow => 10.days)
70 71 72 73 74 75 76 77 |
# File 'lib/rrd/base.rb', line 70 def resize(rra_num, ) info = self.info step = info["step"] rra_step = info["rra[#{rra_num}].pdp_per_row"] action = .keys.first.to_s.upcase delta = (.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 = {}) ⇒ Object
See RRD::Wrapper.restore
80 81 82 83 84 |
# File 'lib/rrd/base.rb', line 80 def restore(xml_file, = {}) = .clone line_params = RRD.to_line_parameters(, RESTORE_FLAGS) Wrapper.restore(xml_file, rrd_file, *line_params) end |
#starts_at ⇒ Object Also known as: first
Returns a time object with the first entered value date
87 88 89 |
# File 'lib/rrd/base.rb', line 87 def starts_at Time.at Wrapper.first(rrd_file) end |
#update(time, *data) ⇒ Object
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
95 96 97 98 99 100 |
# File 'lib/rrd/base.rb', line 95 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 |