Class: Kurchatov::Monitor::Task

Inherits:
Object
  • Object
show all
Includes:
Kurchatov::Mixin::Event
Defined in:
lib/kurchatov/monitor.rb

Constant Summary

Constants included from Kurchatov::Mixin::Event

Kurchatov::Mixin::Event::EVENT_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Kurchatov::Mixin::Event

#event

Methods included from Kurchatov::Mixin::Queue

#events

Constructor Details

#initialize(plugin) ⇒ Task

Returns a new instance of Task.



9
10
11
12
13
14
15
# File 'lib/kurchatov/monitor.rb', line 9

def initialize(plugin)
  @plugin = plugin
  @thread = Thread.new { @plugin.start! }
  @count_errors = 0
  @last_error = nil
  @last_error_at = nil
end

Instance Attribute Details

#count_errorsObject (readonly)

Returns the value of attribute count_errors.



7
8
9
# File 'lib/kurchatov/monitor.rb', line 7

def count_errors
  @count_errors
end

#instanceObject

Returns the value of attribute instance.



6
7
8
# File 'lib/kurchatov/monitor.rb', line 6

def instance
  @instance
end

#last_errorObject (readonly)

Returns the value of attribute last_error.



7
8
9
# File 'lib/kurchatov/monitor.rb', line 7

def last_error
  @last_error
end

#last_error_atObject (readonly)

Returns the value of attribute last_error_at.



7
8
9
# File 'lib/kurchatov/monitor.rb', line 7

def last_error_at
  @last_error_at
end

#threadObject

Returns the value of attribute thread.



6
7
8
# File 'lib/kurchatov/monitor.rb', line 6

def thread
  @thread
end

Instance Method Details

#configObject



21
22
23
# File 'lib/kurchatov/monitor.rb', line 21

def config
  @plugin.plugin_config
end

#died?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kurchatov/monitor.rb', line 33

def died?
  return false if @thread.alive?
  # thread died, join and extract error
  begin
    @thread.join # call error
  rescue => e
    desc = "Plugin '#{@plugin.name}' died. #{e.class}: #{e}\n." +
      "Trace:  #{e.backtrace.join("\n")}"
    @count_errors += 1
    @last_error = desc
    @last_error_at = Time.now
    Log.error(desc)
    unless @plugin.ignore_errors
      event(:service => "plugin #{@plugin.name} errors", :desc => desc, :state => 'critical')
    end
  end
  @thread = Thread.new { @plugin.start! }
  true
end

#nameObject



17
18
19
# File 'lib/kurchatov/monitor.rb', line 17

def name
  @plugin.name
end

#stop!Object



25
26
27
# File 'lib/kurchatov/monitor.rb', line 25

def stop!
  Thread.kill(@thread)
end

#stopped?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/kurchatov/monitor.rb', line 29

def stopped?
  @plugin.stopped?
end