Class: Cellumon

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/cellumon.rb

Constant Summary collapse

MONITORS =
{
  thread_survey: 30,
  thread_report: 15,
  thread_summary: 3,
  memory_count: 13,
  threads_and_memory: 45
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cellumon

Returns a new instance of Cellumon.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cellumon.rb', line 28

def initialize(options={})
  @semaphor = {}
  @status = {}
  @timers = {}
  @debug = options.fetch(:debug, false)
  @logger = options.fetch(:logger, nil)
  @mark = options.fetch(:mark, false)
  @intervals = MONITORS.dup
  @options = options
  async.start
end

Class Method Details

.start!(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/cellumon.rb', line 9

def start!(options={})
  name = options.delete(:name) || :cellumon
  unless options.fetch(:monitors, nil).is_a? Array
    puts "Cellumon > No monitors specified"
    return
  end
  Cellumon.supervise(as: name, args: [options])
  Celluloid[name]
end

Instance Method Details

#memory_count!Object



70
71
72
# File 'lib/cellumon.rb', line 70

def memory_count!
  trigger!(:memory_count) { console memory }
end

#startObject



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

def start
  if @options[:monitors].is_a?(Array)
    debug("Monitors:") if @debug
    @options[:monitors].each { |monitor|
      debug("* #{monitor} every #{MONITORS[monitor]} seconds.") if @debug
      send("start_#{monitor}!")
    }
  else
    debug("No preconfigured monitors.") if @debug
  end
end

#thread_report!Object



82
83
84
# File 'lib/cellumon.rb', line 82

def thread_report!
  trigger!(:thread_report) { console threads }
end

#thread_summary!Object



78
79
80
# File 'lib/cellumon.rb', line 78

def thread_summary!
  trigger!(:thread_summary) { print " #{Thread.list.count} " }
end

#thread_survey!Object



74
75
76
# File 'lib/cellumon.rb', line 74

def thread_survey!
  trigger!(:thread_survey) { Celluloid.stack_summary }
end

#threads_and_memory!Object



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

def threads_and_memory!
  trigger!(:threads_and_memory) { console "#{threads}; #{memory}" }
end