Class: StatsdListener
- Inherits:
-
Object
- Object
- StatsdListener
- Includes:
- Term::ANSIColor
- Defined in:
- lib/statsd_listener.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(host: nil, port: nil) ⇒ StatsdListener
constructor
A new instance of StatsdListener.
- #run ⇒ Object
Constructor Details
#initialize(host: nil, port: nil) ⇒ StatsdListener
Returns a new instance of StatsdListener.
14 15 16 17 18 19 20 21 22 |
# File 'lib/statsd_listener.rb', line 14 def initialize(host: nil, port: nil) $stdout.sync = true @socket = UDPSocket.new @port = PortSanitizer.sanitize(port) @host = host.nil? ? '127.0.0.1' : host @socket.bind(@host, @port) end |
Class Method Details
.run(port: nil, host: nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/statsd_listener.rb', line 8 def self.run(port: nil, host: nil) puts "Starting MiniStatsd...\n\n" new(host: host, port: port).run end |
Instance Method Details
#run ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/statsd_listener.rb', line 24 def run puts "Listening on #{@host}:#{@port}" while = @socket.recvfrom(@port) extract_metric print_metric end end |