Class: StatsdListener

Inherits:
Object
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/statsd_listener.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ StatsdListener

Returns a new instance of StatsdListener.



14
15
16
17
18
19
20
21
# File 'lib/statsd_listener.rb', line 14

def initialize(args)
  $stdout.sync = true

  @socket = UDPSocket.new
  @port = PortSanitizer.get_port(args)
  
  @socket.bind(nil, @port)
end

Class Method Details

.run(args) ⇒ Object



8
9
10
11
12
# File 'lib/statsd_listener.rb', line 8

def self.run(args)
  puts "Starting MiniStatsd...\n\n"

  new(args).run
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
# File 'lib/statsd_listener.rb', line 23

def run
  puts "Listening on port #{@port}"

  while @message = @socket.recvfrom(@port)
    extract_metric

    print_metric
  end
end