Module: Opstat::SendData

Extended by:
Logging
Defined in:
lib/opstat-client/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

log_level, oplogger, preconfig_logger

Class Method Details

.send_from_queue(q, ex, name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/opstat-client/client.rb', line 11

def self.send_from_queue(q, ex, name)
  #TODO cache-evealuate only at start time
  begin
    @hostname ||= Socket.gethostname
    @ip_address ||= Socket::getaddrinfo(@hostname,"echo",Socket::AF_INET)[0][3]
    data_to_send = {:collected_data => []}


    1.upto(q.size) do
      q.pop do |data|
        data_to_send[:collected_data] << data
      end
    end

    # TODO auto register - assign some unique id for a new host instead of hostname, ip_address pai
    data_to_send[:hostname] = @hostname
    data_to_send[:ip_address] = @ip_address
    data_to_send[:version] = Opstat.version
    custom_tags = Opstat::Config.instance.get('client')['custom_tags']
    data_to_send[:custom_tags] = Opstat::Config.instance.get('client')['custom_tags'] if custom_tags
    data_to_send[:send_data_interval] = Opstat::Config.instance.get('client')['send_data_interval']

    ex.publish data_to_send.to_json, :routing_key => name
  rescue SocketError
    raise "Unable to resolve hostname #{Socket.gethostname}"
  end
end

Instance Method Details

#unbindObject



39
40
41
42
# File 'lib/opstat-client/client.rb', line 39

def unbind
  oplogger.info 'AMQP Connection closed'
#    EventMachine::stop_event_loop
end