Class: RRD::Builder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  options = {:every => 5.minutes, :during => 1.day}.merge options
  # steps and rows must be integer, so we need to convert float values
  archive_steps = (options[:every]/parameters[:step]).to_i
  archive_rows = (options[:during]/options[: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, options = {})
  options = {:type => :gauge, :heartbeat => 10.minutes, :min => 0, :max => :unlimited}.merge options
  options[:max] = "U" if options[:max] == :unlimited
  datasource = "DS:#{name}:#{options[:type].to_s.upcase}:#{options[:heartbeat]}:#{options[:min]}:#{options[: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