Class: SimpleMetrics::UDPServer

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_metrics/udp_server.rb

Instance Method Summary collapse

Instance Method Details

#startObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/simple_metrics/udp_server.rb', line 34

def start
  SimpleMetrics.logger.info "SERVER: starting up on #{host}:#{port}..."

  trap('TERM') { stop }
  trap('INT')  { stop }

  DataPointRepository.ensure_collections_exist

  EM.run do
    EM.open_datagram_socket(host, port, SimpleMetrics::ClientHandler) do |con|
      EventMachine::add_periodic_timer(flush_interval) do
        SimpleMetrics.logger.debug "SERVER: period timer triggered after #{flush_interval} seconds"

        EM.defer { SimpleMetrics::Importer.flush_raw(ClientHandler.get_and_clear_data) } 
      end
    end
  end
end

#stopObject



53
54
55
56
# File 'lib/simple_metrics/udp_server.rb', line 53

def stop
  SimpleMetrics.logger.info "EventMachine stop"
  EM.stop
end

#to_sObject



58
59
60
# File 'lib/simple_metrics/udp_server.rb', line 58

def to_s
  "#{host}:#{port}"
end