Class: RRD::Builder
- Inherits:
-
Object
- Object
- RRD::Builder
- Defined in:
- lib/rrd/builder.rb
Constant Summary collapse
- DATASOURCE_TYPES =
[:gauge, :counter, :derive, :absolute]
- ARCHIVE_TYPES =
[:average, :min, :max, :last]
Instance Attribute Summary collapse
-
#archives ⇒ Object
Returns the value of attribute archives.
-
#datasources ⇒ Object
Returns the value of attribute datasources.
-
#output ⇒ Object
Returns the value of attribute output.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Instance Method Summary collapse
- #archive(consolidation_function, options = {}) ⇒ Object
- #datasource(name, options = {}) ⇒ Object
-
#initialize(output, parameters = {}) ⇒ Builder
constructor
A new instance of Builder.
- #save ⇒ Object
Constructor Details
#initialize(output, parameters = {}) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 14 15 16 17 |
# File 'lib/rrd/builder.rb', line 9 def initialize(output, parameters = {}) @output = output @parameters = {:step => 5.minutes, :start => Time.now - 10.seconds }.merge parameters @parameters[:start] = @parameters[:start].to_i @datasources = [] @archives = [] end |
Instance Attribute Details
#archives ⇒ Object
Returns the value of attribute archives.
4 5 6 |
# File 'lib/rrd/builder.rb', line 4 def archives @archives end |
#datasources ⇒ Object
Returns the value of attribute datasources.
4 5 6 |
# File 'lib/rrd/builder.rb', line 4 def datasources @datasources end |
#output ⇒ Object
Returns the value of attribute output.
4 5 6 |
# File 'lib/rrd/builder.rb', line 4 def output @output end |
#parameters ⇒ Object
Returns the value of attribute parameters.
4 5 6 |
# File 'lib/rrd/builder.rb', line 4 def parameters @parameters end |
Instance Method Details
#archive(consolidation_function, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/rrd/builder.rb', line 27 def archive(consolidation_function, = {}) = {:every => 5.minutes, :during => 1.day}.merge # steps and rows must be integer, so we need to convert float values archive_steps = ([:every]/parameters[:step]).to_i archive_rows = ([:during]/[:every]).to_i archive = "RRA:#{consolidation_function.to_s.upcase}:0.5:#{archive_steps}:#{archive_rows}" archives << archive archive end |
#datasource(name, options = {}) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rrd/builder.rb', line 19 def datasource(name, = {}) = {:type => :gauge, :heartbeat => 10.minutes, :min => 0, :max => :unlimited}.merge [:max] = "U" if [:max] == :unlimited datasource = "DS:#{name}:#{[:type].to_s.upcase}:#{[:heartbeat]}:#{[:min]}:#{[:max]}" datasources << datasource datasource end |
#save ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/rrd/builder.rb', line 37 def save args = [output] line_parameters = RRD.to_line_parameters(parameters) args += line_parameters args += datasources args += archives Wrapper.create(*args) end |