Class: What::Modules::Unicorn

Inherits:
Base
  • Object
show all
Defined in:
lib/what/modules/unicorn.rb

Constant Summary collapse

DEFAULTS =
{
  'warning' => 1,
  'alert'   => 0
}

Instance Method Summary collapse

Methods inherited from Base

#name, #status

Constructor Details

#initializeUnicorn

Returns a new instance of Unicorn.



8
9
10
11
# File 'lib/what/modules/unicorn.rb', line 8

def initialize
  super
  @unicorns = []
end

Instance Method Details

#check!Object



13
14
15
16
17
18
# File 'lib/what/modules/unicorn.rb', line 13

def check!
  @unicorns = `ps aux`.split("\n").grep(/unicorn_rails worker/).map do |ln|
                ln =~ /^\w+\s+(\d+).*(\d+:\d\d(?:\.\d\d)?) unicorn/
                {'pid' => $1, 'cpu_time' => $2}
              end
end

#detailsObject



30
31
32
# File 'lib/what/modules/unicorn.rb', line 30

def details
  {'workers' => @unicorns.count, 'details' => @unicorns}
end

#healthObject



20
21
22
23
24
25
26
27
28
# File 'lib/what/modules/unicorn.rb', line 20

def health
  if @unicorns.count > @config['warning']
    'ok'
  elsif @unicorns.count > @config['alert']
    'warning'
  else
    'alert'
  end
end