Class: RRD::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/rrd/graph.rb

Constant Summary collapse

GRAPH_OPTIONS =
[:color, :label]
DEF_OPTIONS =
[:from]
GRAPH_FLAGS =
[:only_graph, :full_size_mode, :rigid, :alt_autoscale, :no_gridfit,
:alt_y_grid, :logarithmic, :no_legend, :force_rules_legend, :lazy,
:pango_markup, :slope_mode, :interlaced, :disable_rrdtool_tag]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, parameters = {}) ⇒ Graph

Returns a new instance of Graph.



12
13
14
15
16
17
18
19
20
21
# File 'lib/rrd/graph.rb', line 12

def initialize(output, parameters = {})
  @output = output
  
  @parameters = {:start => Time.now - 1.day, :end => Time.now, :title => ""}.merge parameters
  @parameters[:start] = @parameters[:start].to_i
  @parameters[:end] = @parameters[:end].to_i
  
  @definitions = []
  @printables = []
end

Instance Attribute Details

#definitionsObject

Returns the value of attribute definitions.



10
11
12
# File 'lib/rrd/graph.rb', line 10

def definitions
  @definitions
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/rrd/graph.rb', line 10

def output
  @output
end

#parametersObject

Returns the value of attribute parameters.



10
11
12
# File 'lib/rrd/graph.rb', line 10

def parameters
  @parameters
end

#printablesObject

Returns the value of attribute printables.



10
11
12
# File 'lib/rrd/graph.rb', line 10

def printables
  @printables
end

Instance Method Details

#area(rrd_file, options) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/rrd/graph.rb', line 88

def area(rrd_file, options)
  dataset = options.reject {|name, value| GRAPH_OPTIONS.include?(name.to_sym)}
  name = "#{dataset.keys.first}_#{dataset.values.first.to_s}"
  options = {:data => name}.merge(options)
  
  definition = for_rrd_data name, {:from => rrd_file}.merge(dataset)
  printable = draw_area options
  [definition, printable]
end

#draw_area(options) ⇒ Object



74
75
76
# File 'lib/rrd/graph.rb', line 74

def draw_area(options)
  draw("AREA", options)
end

#draw_line(options) ⇒ Object



68
69
70
71
72
# File 'lib/rrd/graph.rb', line 68

def draw_line(options)
  options = {:width => 1}.merge options
  type = "LINE#{options[:width]}"
  draw(type, options)
end

#for_rrd_data(data_name, options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rrd/graph.rb', line 23

def for_rrd_data(data_name, options)
  dataset = options.reject {|name, value| DEF_OPTIONS.include?(name.to_sym)}
  start_at = dataset[:start] && dataset.delete(:start)
  end_at   = dataset[:end] && dataset.delete(:end)
  step     = dataset[:step] && dataset.delete(:step)

  definition = "DEF:#{data_name}=#{options[:from]}:#{dataset.keys.first}:#{dataset.values.first.to_s.upcase}"
  definition += ":step=#{step.to_i}" unless step.nil?
  definition += ":start=#{start_at.to_i}" unless start_at.nil?
  definition += ":end=#{end_at.to_i}" unless end_at.nil?

  definitions << definition
  definition
end

#line(rrd_file, options) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/rrd/graph.rb', line 78

def line(rrd_file, options)
  dataset = options.reject {|name, value| GRAPH_OPTIONS.include?(name.to_sym)}
  name = "#{dataset.keys.first}_#{dataset.values.first.to_s}"
  options = {:data => name}.merge(options)
  
  definition = for_rrd_data name, {:from => rrd_file}.merge(dataset)
  printable = draw_line options
  [definition, printable]
end


50
51
52
53
54
# File 'lib/rrd/graph.rb', line 50

def print_comment(comment)
  printable = "COMMENT:#{comment}"
  printables << printable
  printable
end


62
63
64
65
66
# File 'lib/rrd/graph.rb', line 62

def print_value(value_name, options)
  printable = "GPRINT:#{value_name}:#{options[:format]}"
  printables << printable
  printable
end

#saveObject



98
99
100
# File 'lib/rrd/graph.rb', line 98

def save    
  Wrapper.graph(*generate_args)
end

#shift(options) ⇒ Object



56
57
58
59
60
# File 'lib/rrd/graph.rb', line 56

def shift(options)
  definition = "SHIFT:#{options.keys.first}:#{options.values.first.to_i}"
  definitions << definition
  definition
end

#using_calculated_data(data_name, options) ⇒ Object



38
39
40
41
42
# File 'lib/rrd/graph.rb', line 38

def using_calculated_data(data_name, options)
  definition = "CDEF:#{data_name}=#{options[:calc]}"
  definitions << definition
  definition
end

#using_value(value_name, options) ⇒ Object



44
45
46
47
48
# File 'lib/rrd/graph.rb', line 44

def using_value(value_name, options)
  definition = "VDEF:#{value_name}=#{options[:calc]}"
  definitions << definition
  definition
end