Class: Async::Service::Supervisor::Monitor
- Inherits:
-
Object
- Object
- Async::Service::Supervisor::Monitor
- 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
Instance Method Summary collapse
-
#as_json ⇒ Object
Serialize the monitor state for JSON representation.
-
#initialize(interval: 1.0) ⇒ Monitor
constructor
Initialize a new monitor.
-
#run(parent: Async::Task.current) ⇒ Object
Run the utilization monitor.
-
#run_once ⇒ Object
Run one iteration of the monitor.
-
#status ⇒ Object
Get aggregated utilization status by service name.
-
#to_json ⇒ Object
Serialize to JSON string.
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_json ⇒ Object
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_once ⇒ Object
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 |
#status ⇒ Object
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_json ⇒ Object
Serialize to JSON string.
30 31 32 |
# File 'lib/async/service/supervisor/monitor.rb', line 30 def to_json(...) as_json.to_json(...) end |