Module: MultiStatsd

Defined in:
lib/multi-statsd.rb,
lib/multi-statsd/server.rb,
lib/multi-statsd/version.rb,
lib/multi-statsd/backends/base.rb

Overview

MultiStatsd namespace

Defined Under Namespace

Modules: Backend Classes: Server

Constant Summary collapse

VERSION =

Gem version

"0.0.1"

Class Method Summary collapse

Class Method Details

.loggerLogger

Return the logger

Returns:

  • (Logger)


19
20
21
22
23
24
# File 'lib/multi-statsd.rb', line 19

def self.logger
  return @logger if defined?(@logger)
  log = Logger.new(STDOUT)
  log.level = 2
  @logger = EM::Logger.new(log)
end

.logger=(logger) ⇒ Object

Assign a logger

Parameters:

  • logger (Logger)


13
14
15
# File 'lib/multi-statsd.rb', line 13

def self.logger=(logger)
  @logger = logger.kind_of?(EM::Logger) ? logger : EM::Logger.new(logger)
end

.start(options) ⇒ thread

Start up the Eventmachine reactor loop in a separate thread give a set of options.

This is a test
This is another test

Parameters:

  • options (Hash)

    Set of options

Returns:

  • (thread)

    Thread which is running the eventmachine loop



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/multi-statsd.rb', line 31

def self.start(options)
  thread = Thread.new do
    EM.run do
      backends = []
      options['backends'].each_pair do |name, options|
        backend = options.delete('backend')
        begin
          require "multi-statsd/backends/#{backend.downcase}"
        rescue LoadError
          raise MultiStatsd::Backend::Error, "Cannot load file multi-statsd/backends/#{backend.downcase}"
        end
        if !MultiStatsd::Backend.const_defined?(backend)
          raise MultiStatsd::Backend::Error, "No such back end: MultiStatsd::Backend::#{backend}"
        else
          logger.info "Adding backend #{backend} :: #{name}"
          backends << MultiStatsd::Backend.const_get(backend).new(name, options)
        end
      end

      EM::open_datagram_socket(
        (options['host'] || '127.0.0.1'),
        (options['port'] || 8125),
        MultiStatsd::Server,
        backends
      )
      logger.info "multi-statsd starting up on #{options['host']}:#{options['port']}"
    end
  end
  
  thread.abort_on_exception = true
  thread
end

.stopObject

Stop the Eventmachine reactor loop



65
66
67
68
# File 'lib/multi-statsd.rb', line 65

def self.stop
  logger.info "multi-statsd shutting down"
  EM.next_tick { EM.stop }
end