Async::Service::SupervisorSourceAsyncServiceSupervisorMonitor

class Monitor

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

Subclasses should override #run_once to implement specific monitoring logic.

Definitions

def initialize(interval: 1.0)

Initialize a new monitor.

Signature

parameter interval Numeric

The interval in seconds between each invocation of #run_once.

Implementation

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

def as_json(...)

Serialize the monitor state for JSON representation.

Signature

returns Hash

An empty hash by default; subclasses should override to include relevant state.

Implementation

def as_json(...)
	{}
end

def to_json(...)

Serialize to JSON string.

Implementation

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

def status

Get aggregated utilization status by service name.

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

Signature

returns Hash

Hash with type and data keys.

Implementation

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

def run_once

Run one iteration of the monitor.

Implementation

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

def run(parent: Async::Task.current)

Run the utilization monitor.

Periodically aggregates utilization data from all workers.

Signature

returns Async::Task

The task that is running the utilization monitor.

Implementation

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