Class: DroneCollectd::CollectdPacket
- Inherits:
-
Object
- Object
- DroneCollectd::CollectdPacket
- Defined in:
- lib/drone_collectd/parser.rb,
lib/drone_collectd/parser_old.rb
Defined Under Namespace
Classes: Packet, Part, ValuePart, ValuePartData
Constant Summary collapse
- HOST =
part type
0x0000
- TIME =
0x0001
- PLUGIN =
0x0002
- PLUGIN_INSTANCE =
0x0003
- TYPE =
0x0004
- TYPE_INSTANCE =
0x0005
- VALUES =
0x0006
- INTERVAL =
0x0007
- MESSAGE =
0x0100
- SEVERITY =
0x0101
- COUNTER =
data type
0
- GAUGE =
1
- DERIVE =
2
- ABSOLUTE =
3
- STRING_TYPES =
[HOST, PLUGIN, PLUGIN_INSTANCE, TYPE, TYPE_INSTANCE, MESSAGE].freeze
- INTEGER_TYPES =
[TIME, INTERVAL, SEVERITY].freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#plugin ⇒ Object
Returns the value of attribute plugin.
-
#plugin_instance ⇒ Object
Returns the value of attribute plugin_instance.
-
#time ⇒ Object
Returns the value of attribute time.
-
#type ⇒ Object
Returns the value of attribute type.
-
#type_instance ⇒ Object
Returns the value of attribute type_instance.
Instance Method Summary collapse
- #add_value(type, value) ⇒ Object
- #build_packet ⇒ Object
-
#initialize ⇒ CollectdPacket
constructor
A new instance of CollectdPacket.
- #method_missing(m, *args) ⇒ Object
Constructor Details
#initialize ⇒ CollectdPacket
Returns a new instance of CollectdPacket.
26 27 28 29 |
# File 'lib/drone_collectd/parser.rb', line 26 def initialize @values = [] @values_type = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/drone_collectd/parser_old.rb', line 133 def method_missing(m, *args) if @packet.respond_to?(m) @packet.send(m, *args) else raise NoMethodError, m.to_s end end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
22 23 24 |
# File 'lib/drone_collectd/parser.rb', line 22 def host @host end |
#interval ⇒ Object
Returns the value of attribute interval.
22 23 24 |
# File 'lib/drone_collectd/parser.rb', line 22 def interval @interval end |
#plugin ⇒ Object
Returns the value of attribute plugin.
23 24 25 |
# File 'lib/drone_collectd/parser.rb', line 23 def plugin @plugin end |
#plugin_instance ⇒ Object
Returns the value of attribute plugin_instance.
23 24 25 |
# File 'lib/drone_collectd/parser.rb', line 23 def plugin_instance @plugin_instance end |
#time ⇒ Object
Returns the value of attribute time.
22 23 24 |
# File 'lib/drone_collectd/parser.rb', line 22 def time @time end |
#type ⇒ Object
Returns the value of attribute type.
24 25 26 |
# File 'lib/drone_collectd/parser.rb', line 24 def type @type end |
#type_instance ⇒ Object
Returns the value of attribute type_instance.
24 25 26 |
# File 'lib/drone_collectd/parser.rb', line 24 def type_instance @type_instance end |
Instance Method Details
#add_value(type, value) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/drone_collectd/parser.rb', line 31 def add_value(type, value) raise(ArgumentError, "unknown type: #{type}") unless CollectdPacket::const_defined?(type.to_s.upcase) data_type = CollectdPacket::const_get(type.to_s.upcase) @values_type << data_type @values << value end |
#build_packet ⇒ Object
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 |
# File 'lib/drone_collectd/parser.rb', line 39 def build_packet @pkt = CollectdGenerator::string(HOST, @host) @pkt << CollectdGenerator::number(TIME, @time) @pkt << CollectdGenerator::number(INTERVAL, @interval) @pkt << CollectdGenerator::string(PLUGIN, @plugin) @pkt << CollectdGenerator::string(PLUGIN_INSTANCE, @plugin_instance) @pkt << CollectdGenerator::string(TYPE, @type) @pkt << CollectdGenerator::string(TYPE_INSTANCE, @type_instance) # values part header @pkt << [VALUES, 4 + 2 + (@values.size * 9), @values.size].pack('nnn') # types @pkt << @values_type.pack('C*') # and the values @values.each.with_index do |v, i| case @values_type[i] when COUNTER, ABSOLUTE, DERIVE @pkt << [v >> 32, v & 0xffffffff].pack("NN") when GAUGE @pkt << [v].pack('E') else raise "unknown type: #{@values_type[i]}" end end @pkt end |