Class: RRD::Graph
- Inherits:
-
Object
- Object
- RRD::Graph
- 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
-
#definitions ⇒ Object
Returns the value of attribute definitions.
-
#output ⇒ Object
Returns the value of attribute output.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#printables ⇒ Object
Returns the value of attribute printables.
Instance Method Summary collapse
- #area(rrd_file, options) ⇒ Object
- #draw_area(options) ⇒ Object
- #draw_line(options) ⇒ Object
- #for_rrd_data(data_name, options) ⇒ Object
-
#initialize(output, parameters = {}) ⇒ Graph
constructor
A new instance of Graph.
- #line(rrd_file, options) ⇒ Object
- #print_comment(comment) ⇒ Object
- #print_value(value_name, options) ⇒ Object
- #save ⇒ Object
- #shift(options) ⇒ Object
- #using_calculated_data(data_name, options) ⇒ Object
- #using_value(value_name, options) ⇒ Object
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
#definitions ⇒ Object
Returns the value of attribute definitions.
10 11 12 |
# File 'lib/rrd/graph.rb', line 10 def definitions @definitions end |
#output ⇒ Object
Returns the value of attribute output.
10 11 12 |
# File 'lib/rrd/graph.rb', line 10 def output @output end |
#parameters ⇒ Object
Returns the value of attribute parameters.
10 11 12 |
# File 'lib/rrd/graph.rb', line 10 def parameters @parameters end |
#printables ⇒ Object
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, ) dataset = .reject {|name, value| GRAPH_OPTIONS.include?(name.to_sym)} name = "#{dataset.keys.first}_#{dataset.values.first.to_s}" = {:data => name}.merge() definition = for_rrd_data name, {:from => rrd_file}.merge(dataset) printable = draw_area [definition, printable] end |
#draw_area(options) ⇒ Object
74 75 76 |
# File 'lib/rrd/graph.rb', line 74 def draw_area() draw("AREA", ) end |
#draw_line(options) ⇒ Object
68 69 70 71 72 |
# File 'lib/rrd/graph.rb', line 68 def draw_line() = {:width => 1}.merge type = "LINE#{options[:width]}" draw(type, ) 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, ) dataset = .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, ) dataset = .reject {|name, value| GRAPH_OPTIONS.include?(name.to_sym)} name = "#{dataset.keys.first}_#{dataset.values.first.to_s}" = {:data => name}.merge() definition = for_rrd_data name, {:from => rrd_file}.merge(dataset) printable = draw_line [definition, printable] end |
#print_comment(comment) ⇒ Object
50 51 52 53 54 |
# File 'lib/rrd/graph.rb', line 50 def print_comment(comment) printable = "COMMENT:#{comment}" printables << printable printable end |
#print_value(value_name, options) ⇒ Object
62 63 64 65 66 |
# File 'lib/rrd/graph.rb', line 62 def print_value(value_name, ) printable = "GPRINT:#{value_name}:#{options[:format]}" printables << printable printable end |
#save ⇒ Object
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() 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, ) 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, ) definition = "VDEF:#{value_name}=#{options[:calc]}" definitions << definition definition end |