Module: Deimos

Defined in:
lib/deimos.rb,
lib/deimos/logger.rb,
lib/deimos/version.rb,
lib/deimos/status/runner.rb,
lib/deimos/status/manager.rb,
lib/deimos/metrics/manager.rb,
lib/deimos/endpoints/status.rb,
lib/deimos/endpoints/metrics.rb

Defined Under Namespace

Modules: Endpoints, Metrics, Status Classes: Logger

Constant Summary collapse

VERSION =
"0.2.9"

Class Method Summary collapse

Class Method Details

.applicationObject



34
35
36
37
38
39
# File 'lib/deimos.rb', line 34

def application
  @application ||= Rack::Builder.new do
    Deimos.middleware.each { |m| use m }
    run Rack::URLMap.new(Deimos.applications)
  end
end

.applicationsObject



59
60
61
62
63
64
65
66
# File 'lib/deimos.rb', line 59

def applications
  load! unless loaded?

  @applications ||= {
    "/status" => Deimos::Endpoints::Status.new(status: status),
    "/metrics" => Deimos::Endpoints::Metrics.new(metrics: metrics)
  }.merge(config.applications)
end

.boot!Object



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

def boot!
  Thread.new do
    ::Rack::Handler::WEBrick.run(application, {
      Host: Deimos.config.bind,
      Port: Deimos.config.port,
      Logger: Deimos.logger,
      AccessLog: []
    })
  end
end

.configObject



41
42
43
44
45
46
47
48
49
# File 'lib/deimos.rb', line 41

def config
  @config ||= OpenStruct.new.tap do |x|
    x.log_level    = ENV.fetch("LOG_LEVEL", ::Logger::INFO)
    x.port         = ENV.fetch("PORT", 5000)
    x.bind         = ENV.fetch("BIND_IP", "0.0.0.0")
    x.applications = {}
    x.middleware   = []
  end
end

.configure {|config| ... } ⇒ Object

Yields:



51
52
53
# File 'lib/deimos.rb', line 51

def configure
  yield(config)
end

.load!Object



80
81
82
83
84
# File 'lib/deimos.rb', line 80

def load!
  require 'deimos/endpoints/status'
  require 'deimos/endpoints/metrics'
  @loaded = true
end

.loaded?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/deimos.rb', line 86

def loaded?
  @loaded
end

.loggerObject



76
77
78
# File 'lib/deimos.rb', line 76

def logger
  @logger ||= Huyegger::Logger.new(::Logger.new(STDOUT).tap {|x| x.level = config.log_level})
end

.metricsObject



72
73
74
# File 'lib/deimos.rb', line 72

def metrics
  @metrics ||= Deimos::Metrics::Manager.new
end

.middlewareObject



55
56
57
# File 'lib/deimos.rb', line 55

def middleware
  @middleware ||= [Rack::Deflater, Deimos::Logger] | config.middleware
end

.statusObject



68
69
70
# File 'lib/deimos.rb', line 68

def status
  @status ||= Deimos::Status::Manager.new
end