Class: RRD::Header

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

Constant Summary collapse

"RRD\0"
8.642135E130

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Header

Returns a new instance of Header.



10
11
12
13
14
15
16
17
18
19
# File 'lib/rrd/header.rb', line 10

def initialize(options)
  @version = options[:version] || "0003"
  @last_update = options[:last_update] # || Time.now
  @step = options[:step] || 10
  @endianess = options[:endianess] || :little
  @alignment = options[:alignment] || 4

  @rra = options[:rra] || []
  @datasources = options[:datasources] || []
end

Instance Attribute Details

#alignmentObject (readonly)

Returns the value of attribute alignment.



6
7
8
# File 'lib/rrd/header.rb', line 6

def alignment
  @alignment
end

#datasourcesObject (readonly)

Returns the value of attribute datasources.



8
9
10
# File 'lib/rrd/header.rb', line 8

def datasources
  @datasources
end

#endianessObject (readonly)

Returns the value of attribute endianess.



6
7
8
# File 'lib/rrd/header.rb', line 6

def endianess
  @endianess
end

#last_updateObject (readonly)

Returns the value of attribute last_update.



6
7
8
# File 'lib/rrd/header.rb', line 6

def last_update
  @last_update
end

#rraObject (readonly)

Returns the value of attribute rra.



8
9
10
# File 'lib/rrd/header.rb', line 8

def rra
  @rra
end

#stepObject (readonly)

Returns the value of attribute step.



6
7
8
# File 'lib/rrd/header.rb', line 6

def step
  @step
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/rrd/header.rb', line 6

def version
  @version
end

Class Method Details

.parse(reader) ⇒ Object



26
27
28
29
30
31
32
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
81
82
83
84
# File 'lib/rrd/header.rb', line 26

def self.parse(reader)
  reader.seek(0) # rewind to start

  read_cookie(reader)

  options = {}

  options[:version] = reader.read(5, "a*").first

  read_double_cookie(reader, options)

  datasources_count, rra_count, @step = reader.read(24, "QQQ")

  global_params = reader.read_uniparams(10)

  options[:datasources] = []
  datasources_count.times do |i|
    options[:datasources] << RRD::DataSource.parse(reader)
  end

  options[:rra] = []
  rra_pointer = 0
  rra_count.times do |i|
    rra = RRD::Archive.parse(reader)

    rra.data_pointer = rra_pointer
    rra_pointer += rra.rows * datasources_count * 8

    options[:rra] << rra
  end

  last_update, last_update_msec = reader.read(16, "QQ")

  options[:last_update] = Time.at(last_update.to_f + (last_update_msec.to_f / 1000000))

  datasources_count.times do |i|
    datasource = options[:datasources][i]

    datasource.last_ds = reader.read_string(30, "A*")
    reader.align
    params = reader.read_uniparams(10)
    datasource.unknown_seconds = params[0].to_i
    datasource.last_value = params[1].to_f
  end

  rra_count.times do |rra_index|
    datasources_count.times do |ds_index|
      cdp = RRD::CDP.parse(reader, options[:rra][rra_index])
      options[:rra][rra_index].cdp[ds_index] = cdp
      options[:datasources][ds_index].cdp[rra_index] = cdp
    end
  end

  rra_count.times do |rra_index|
    options[:rra][rra_index].current_row = reader.read(8, "Q").first
  end

  Header.new(options)
end

Instance Method Details

#setup_reader(reader) ⇒ Object



21
22
23
24
# File 'lib/rrd/header.rb', line 21

def setup_reader(reader)
  reader.endianess = endianess
  reader.alignment = alignment
end