Class: GmonPacket
- Inherits:
-
Object
- Object
- GmonPacket
- Defined in:
- lib/logstash/inputs/ganglia/gmondpacket.rb
Instance Method Summary collapse
- #data? ⇒ Boolean
- #heartbeat? ⇒ Boolean
-
#initialize(packet) ⇒ GmonPacket
constructor
A new instance of GmonPacket.
- #meta? ⇒ Boolean
-
#name_to_type(name, metadata) ⇒ Object
Does lookup of metricname in metadata table to find the correct type.
-
#parse_data(metadata) ⇒ Object
Parsing a data packet : type 133..135 Requires metadata to be available for correct parsing of the value.
-
#parse_metadata ⇒ Object
Parsing a metadata packet : type 128.
-
#parse_value(type) ⇒ Object
Parsing a specific value of type github.com/ganglia/monitor-core/blob/master/gmond/gmond.c#L1527.
Constructor Details
#initialize(packet) ⇒ GmonPacket
Returns a new instance of GmonPacket.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 15 def initialize(packet) @xdr=XDR::Reader.new(StringIO.new(packet)) # Read packet type type=@xdr.uint32 case type when 128 @type=:meta when 132 @type=:heartbeat when 133..134 @type=:data when 135 @type=:gexec else @type=:unknown end end |
Instance Method Details
#data? ⇒ Boolean
38 39 40 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 38 def data? @type == :data end |
#heartbeat? ⇒ Boolean
34 35 36 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 34 def heartbeat? @type == :hearbeat end |
#meta? ⇒ Boolean
42 43 44 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 42 def @type == :meta end |
#name_to_type(name, metadata) ⇒ Object
Does lookup of metricname in metadata table to find the correct type
138 139 140 141 142 143 144 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 138 def name_to_type(name,) # Lookup this metric metadata =[name] return nil if .nil? return ['type'] end |
#parse_data(metadata) ⇒ Object
Parsing a data packet : type 133..135 Requires metadata to be available for correct parsing of the value
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 87 def parse_data() data=Hash.new data['hostname']=@xdr.string metricname=@xdr.string data['name']=metricname data['spoof']=@xdr.uint32 data['format']=@xdr.string metrictype=name_to_type(metricname,) if metrictype.nil? # Probably we got a data packet before a metadata packet #puts "Received datapacket without metadata packet" return nil end data['val']=parse_value(metrictype) # If we received a packet, last update was 0 time ago data['tn']=0 return data end |
#parse_metadata ⇒ Object
Parsing a metadata packet : type 128
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 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 47 def =Hash.new ['hostname']=@xdr.string ['name']=@xdr.string ['spoof']=@xdr.uint32 ['type']=@xdr.string ['name2']=@xdr.string ['units']=@xdr.string slope=@xdr.uint32 case slope when 0 ['slope']= 'zero' when 1 ['slope']= 'positive' when 2 ['slope']= 'negative' when 3 ['slope']= 'both' when 4 ['slope']= 'unspecified' end ['tmax']=@xdr.uint32 ['dmax']=@xdr.uint32 nrelements=@xdr.uint32 ['nrelements']=nrelements unless nrelements.nil? extra={} for i in 1..nrelements name=@xdr.string extra[name]=@xdr.string end ['extra']=extra end return end |
#parse_value(type) ⇒ Object
Parsing a specific value of type github.com/ganglia/monitor-core/blob/master/gmond/gmond.c#L1527
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/logstash/inputs/ganglia/gmondpacket.rb', line 114 def parse_value(type) value=:unknown case type when "int16" value=@xdr.int16 when "uint16" value=@xdr.uint16 when "uint32" value=@xdr.uint32 when "int32" value=@xdr.int32 when "float" value=@xdr.float32 when "double" value=@xdr.float64 when "string" value=@xdr.string else #puts "Received unknown type #{type}" end return value end |