Class: Async::Service::Supervisor::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/async/service/supervisor/monitor.rb

Overview

Base class for supervisor monitors that run periodically within the supervisor process.

Subclasses should override #run_once to implement specific monitoring logic.

Direct Known Subclasses

MemoryMonitor, ProcessMonitor, UtilizationMonitor

Instance Method Summary collapse

Constructor Details

#initialize(interval: 1.0) ⇒ Monitor

Initialize a new monitor.



18
19
20
# File 'lib/async/service/supervisor/monitor.rb', line 18

def initialize(interval: 1.0)
	@interval = interval
end

Instance Method Details

#as_jsonObject

Serialize the monitor state for JSON representation.



25
26
27
# File 'lib/async/service/supervisor/monitor.rb', line 25

def as_json(...)
	{}
end

#run(parent: Async::Task.current) ⇒ Object

Run the utilization monitor.

Periodically aggregates utilization data from all workers.



54
55
56
57
58
59
60
# File 'lib/async/service/supervisor/monitor.rb', line 54

def run(parent: Async::Task.current)
	parent.async do
		Loop.periodic(interval: @interval) do
			self.run_once
		end
	end
end

#run_onceObject

Run one iteration of the monitor.



45
46
47
# File 'lib/async/service/supervisor/monitor.rb', line 45

def run_once
	# This method can be overridden by subclasses to implement specific monitoring logic.
end

#statusObject

Get aggregated utilization status by service name.

Reads utilization data from all registered workers and aggregates it by service name (from supervisor_controller.state).



40
41
42
# File 'lib/async/service/supervisor/monitor.rb', line 40

def status
	{type: self.class.name, data: as_json}
end

#to_jsonObject

Serialize to JSON string.



30
31
32
# File 'lib/async/service/supervisor/monitor.rb', line 30

def to_json(...)
	as_json.to_json(...)
end