Class: CollectdServer::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/collectd_server/packet.rb

Defined Under Namespace

Classes: Host, Interval, Number, Part, Plugin, PluginInstance, Stack, String, Time, Type, TypeInstance, Values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Packet

Returns a new instance of Packet.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/collectd_server/packet.rb', line 9

def initialize(data)
  @parts = []
  data = data.dup # don't modify the data passed in
  while !data.empty?
    type, length = data.slice!(0,4).unpack('nn')
    content_length = length - 4
    content = data.slice!(0, content_length)

    @parts << Part.class_for(type).new(content)
  end
end

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



7
8
9
# File 'lib/collectd_server/packet.rb', line 7

def parts
  @parts
end

Instance Method Details

#to_datapointsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/collectd_server/packet.rb', line 21

def to_datapoints
  datapoints = []
  stack = Stack.new

  @parts.each do |part|

    if part.is_a?(Values) # Values is the last "part"
      datapoints += DatapointBuilder.from_parts(stack.to_a, part)
    else
      stack.update_part(part)
    end
  end

  datapoints
end