Class: CollectdServer::Packet
- Inherits:
-
Object
- Object
- CollectdServer::Packet
- 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
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
-
#initialize(data) ⇒ Packet
constructor
A new instance of Packet.
- #to_datapoints ⇒ Object
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
#parts ⇒ Object (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_datapoints ⇒ Object
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 |