Class: LogStash::Inputs::Ganglia

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/inputs/ganglia.rb

Overview

Read ganglia packets from the network via udp

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Ganglia

Returns a new instance of Ganglia.



24
25
26
27
# File 'lib/logstash/inputs/ganglia.rb', line 24

def initialize(params)
  super
  BasicSocket.do_not_reverse_lookup = true
end

Instance Method Details

#parse_packet(packet) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/logstash/inputs/ganglia.rb', line 98

def parse_packet(packet)
  gmonpacket=GmonPacket.new(packet)
  if gmonpacket.meta?
    # Extract the metadata from the packet
    meta=gmonpacket.
    # Add it to the global metadata of this connection
    @metadata[meta['name']]=meta

    # We are ignoring meta events for putting things on the queue
    @logger.debug("received a meta packet", @metadata)
    return nil
  elsif gmonpacket.data?
    data=gmonpacket.parse_data(@metadata)

    # Check if it was a valid data request
    return nil unless data
    props={ "program" => "ganglia", "log_host" => data["hostname"] }
    %w{dmax tmax slope type units}.each do |info|
      props[info] = @metadata[data["name"]][info]
    end
    return LogStash::Event.new(props)
  else
    # Skipping unknown packet types
    return nil
  end
end

#registerObject



30
31
# File 'lib/logstash/inputs/ganglia.rb', line 30

def register
end

#run(output_queue) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/logstash/inputs/ganglia.rb', line 34

def run(output_queue)
  begin
    udp_listener(output_queue)
  rescue => e
    if !stop?
      @logger.warn("ganglia udp listener died",
                   :address => "#{@host}:#{@port}", :exception => e,
      :backtrace => e.backtrace)
      Stud.stoppable_sleep(5) { stop? }
      retry
    end
  end # begin
end

#stopObject



85
86
87
# File 'lib/logstash/inputs/ganglia.rb', line 85

def stop
  close_udp
end