Class: RRD::Data
- Inherits:
-
Object
- Object
- RRD::Data
- Defined in:
- lib/rrd/data.rb
Instance Attribute Summary collapse
-
#data_start ⇒ Object
readonly
Returns the value of attribute data_start.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#rra ⇒ Object
readonly
Returns the value of attribute rra.
Instance Method Summary collapse
- #fetch(options = {}, &block) ⇒ Object
- #fetch_last ⇒ Object
- #first_update ⇒ Object
-
#initialize(rra, reader, header, data_start) ⇒ Data
constructor
A new instance of Data.
- #last_update ⇒ Object
- #step_time ⇒ Object
Constructor Details
#initialize(rra, reader, header, data_start) ⇒ Data
Returns a new instance of Data.
6 7 8 9 10 11 12 13 |
# File 'lib/rrd/data.rb', line 6 def initialize(rra, reader, header, data_start) @rra = rra @reader = reader @header = header @data_start = data_start header.setup_reader(reader) # update endianess and alignment end |
Instance Attribute Details
#data_start ⇒ Object (readonly)
Returns the value of attribute data_start.
4 5 6 |
# File 'lib/rrd/data.rb', line 4 def data_start @data_start end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/rrd/data.rb', line 4 def header @header end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
4 5 6 |
# File 'lib/rrd/data.rb', line 4 def reader @reader end |
#rra ⇒ Object (readonly)
Returns the value of attribute rra.
4 5 6 |
# File 'lib/rrd/data.rb', line 4 def rra @rra end |
Instance Method Details
#fetch(options = {}, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rrd/data.rb', line 33 def fetch( = {}, &block) row = [:start_row] || 0 rows = [[:rows] || rra.rows, rra.rows].min current_time = first_update columns = [:time] + header.datasources.map(&:name).map(&:to_sym) if [:start_time] start_time = round_time([:start_time].to_i) if current_time < start_time row = ((start_time - current_time) / step_time).floor current_time = start_time end end if [:end_time] end_time = round_time([:end_time].to_i) if end_time < last_update rows = ((end_time - current_time) / step_time).ceil end end if row < head reader.seek(base_position + ((rra.current_row + 1 + row) * row_size)) end data = [] while row < rows if head && row >= head reader.seek(base_position + (row - head) * row_size) # jump to beginning head = nil end current_time += step_time row_data = [current_time] + reader.read(row_size, unpack_formula) row_data = block.call(row_data, columns, ) if block data << row_data row += 1 end data end |
#fetch_last ⇒ Object
27 28 29 30 31 |
# File 'lib/rrd/data.rb', line 27 def fetch_last reader.seek(base_position + rra.current_row * row_size) [last_update] + reader.read(row_size, unpack_formula) end |
#first_update ⇒ Object
15 16 17 |
# File 'lib/rrd/data.rb', line 15 def first_update @start_time = last_update - (rra.rows * step_time) end |
#last_update ⇒ Object
19 20 21 |
# File 'lib/rrd/data.rb', line 19 def last_update @last_update ||= round_time(header.last_update.to_i) end |
#step_time ⇒ Object
23 24 25 |
# File 'lib/rrd/data.rb', line 23 def step_time @step_time ||= header.step * rra.pdpr end |