Class: RRD::Header
- Inherits:
-
Object
- Object
- RRD::Header
- Defined in:
- lib/rrd/header.rb
Constant Summary collapse
- COOKIE_STRING =
"RRD\0"- COOKIE_DOUBLE =
8.642135E130
Instance Attribute Summary collapse
-
#alignment ⇒ Object
readonly
Returns the value of attribute alignment.
-
#datasources ⇒ Object
readonly
Returns the value of attribute datasources.
-
#endianess ⇒ Object
readonly
Returns the value of attribute endianess.
-
#last_update ⇒ Object
readonly
Returns the value of attribute last_update.
-
#rra ⇒ Object
readonly
Returns the value of attribute rra.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Header
constructor
A new instance of Header.
- #setup_reader(reader) ⇒ Object
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() @version = [:version] || "0003" @last_update = [:last_update] # || Time.now @step = [:step] || 10 @endianess = [:endianess] || :little @alignment = [:alignment] || 4 @rra = [:rra] || [] @datasources = [:datasources] || [] end |
Instance Attribute Details
#alignment ⇒ Object (readonly)
Returns the value of attribute alignment.
6 7 8 |
# File 'lib/rrd/header.rb', line 6 def alignment @alignment end |
#datasources ⇒ Object (readonly)
Returns the value of attribute datasources.
8 9 10 |
# File 'lib/rrd/header.rb', line 8 def datasources @datasources end |
#endianess ⇒ Object (readonly)
Returns the value of attribute endianess.
6 7 8 |
# File 'lib/rrd/header.rb', line 6 def endianess @endianess end |
#last_update ⇒ Object (readonly)
Returns the value of attribute last_update.
6 7 8 |
# File 'lib/rrd/header.rb', line 6 def last_update @last_update end |
#rra ⇒ Object (readonly)
Returns the value of attribute rra.
8 9 10 |
# File 'lib/rrd/header.rb', line 8 def rra @rra end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
6 7 8 |
# File 'lib/rrd/header.rb', line 6 def step @step end |
#version ⇒ Object (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 (reader) = {} [:version] = reader.read(5, "a*").first (reader, ) datasources_count, rra_count, @step = reader.read(24, "QQQ") global_params = reader.read_uniparams(10) [:datasources] = [] datasources_count.times do |i| [:datasources] << RRD::DataSource.parse(reader) end [: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 [:rra] << rra end last_update, last_update_msec = reader.read(16, "QQ") [:last_update] = Time.at(last_update.to_f + (last_update_msec.to_f / 1000000)) datasources_count.times do |i| datasource = [: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, [:rra][rra_index]) [:rra][rra_index].cdp[ds_index] = cdp [:datasources][ds_index].cdp[rra_index] = cdp end end rra_count.times do |rra_index| [:rra][rra_index].current_row = reader.read(8, "Q").first end Header.new() 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 |