Class: RRDReader::RRA

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step, h) ⇒ RRA

“rows”=>24, “cur_row”=>1, “pdp_per_row”=>1, “xff”=>0.5, “cdp_prep”=>0,



18
19
20
21
22
23
24
25
26
27
# File 'lib/rrd-grapher/rrd.rb', line 18

def initialize(step, h)
  @step = step
  
  @cf = translate_function( h.delete('cf') )
  @rows = h.delete('rows').to_i
  @cur_row = h.delete('cur_row').to_i
  @pdp_per_row = h.delete('pdp_per_row').to_i
  @xff = h.delete('xff').to_f
  @cdp_prep = h.delete('cdp_prep').to_f
end

Instance Attribute Details

#cfObject (readonly)

Returns the value of attribute cf.



15
16
17
# File 'lib/rrd-grapher/rrd.rb', line 15

def cf
  @cf
end

#current_rowObject (readonly)

Returns the value of attribute current_row.



15
16
17
# File 'lib/rrd-grapher/rrd.rb', line 15

def current_row
  @current_row
end

#rowsObject (readonly)

Returns the value of attribute rows.



15
16
17
# File 'lib/rrd-grapher/rrd.rb', line 15

def rows
  @rows
end

Instance Method Details

#clip_time(from, to, last_update) ⇒ Object

Raises:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rrd-grapher/rrd.rb', line 63

def clip_time(from, to, last_update)
  # compute start/end time for this rra
  # last 
  # first_slot_time = last_update
  diff = to -from
  
  raise InvalidRRARange if diff > duration
  
  # from/to must be a multiple of <interval>
  to = (to / interval).to_i * interval
  from = to - diff
  
  [from, to]
end

#durationObject

<rows> points are stored which translate to a duration of X



47
48
49
# File 'lib/rrd-grapher/rrd.rb', line 47

def duration
  @rows * interval()
end

#intervalObject

one point is saved every X seconds



42
43
44
# File 'lib/rrd-grapher/rrd.rb', line 42

def interval
  @pdp_per_row * @step
end

#to_json(*args) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rrd-grapher/rrd.rb', line 51

def to_json(*args)
  ret = {
    :function => @cf,
    :row => @rows,
    :current_row => @cur_row,
    :interval => self.interval,
    :duration => self.duration
  }
  
  ret.to_json(*args)
end

#translate_function(cf) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/rrd-grapher/rrd.rb', line 31

def translate_function(cf)
  case cf
  when "AVERAGE"  then  :average
  when "MIN"      then  :min
  when "MAX"      then  :max
  else
    raise "Unknown function: #{cf}"
  end
end