Class: CpuInspectCore::Monitor
- Inherits:
-
Object
- Object
- CpuInspectCore::Monitor
- Defined in:
- lib/cpu_inspect_core/monitor.rb
Instance Method Summary collapse
-
#initialize(collector:, backend:, config:) ⇒ Monitor
constructor
A new instance of Monitor.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(collector:, backend:, config:) ⇒ Monitor
Returns a new instance of Monitor.
5 6 7 8 9 10 11 12 |
# File 'lib/cpu_inspect_core/monitor.rb', line 5 def initialize(collector:, backend:, config:) @collector = collector @backend = backend @interval = config.interval @thread = nil @running = false @mutex = Mutex.new end |
Instance Method Details
#running? ⇒ Boolean
41 42 43 |
# File 'lib/cpu_inspect_core/monitor.rb', line 41 def running? @mutex.synchronize { @running } end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cpu_inspect_core/monitor.rb', line 14 def start @mutex.synchronize do return self if @running @running = true @thread = Thread.new { run_loop } @thread.abort_on_exception = false @thread.name = 'cpu_inspect_core' end at_exit { stop } self end |
#stop ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cpu_inspect_core/monitor.rb', line 28 def stop @mutex.synchronize do return unless @running @running = false # :nocov: — @thread is always non-nil here; &. is a nil-safety guard only @thread&.kill @thread&.join(2) # :nocov: @thread = nil end end |