Class: Fractor::PerformanceMonitor
- Inherits:
-
Object
- Object
- Fractor::PerformanceMonitor
- Defined in:
- lib/fractor/performance_monitor.rb
Overview
Monitors and tracks performance metrics for Fractor supervisors and workers.
Collects metrics including:
- Jobs processed count
- Latency statistics (average, p50, p95, p99)
- Throughput (jobs/second)
- Worker utilization
- Queue depth over time
- Memory usage
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#supervisor ⇒ Object
readonly
Returns the value of attribute supervisor.
Instance Method Summary collapse
-
#initialize(supervisor, sample_interval: 1.0) ⇒ PerformanceMonitor
constructor
Create a new performance monitor.
-
#monitoring? ⇒ Boolean
Check if currently monitoring.
-
#record_job(latency, success: true) ⇒ void
Record a job completion.
-
#report ⇒ String
Generate a human-readable report.
-
#snapshot ⇒ Hash
Get current metrics snapshot.
-
#start ⇒ void
Start monitoring.
-
#stop ⇒ void
Stop monitoring.
-
#to_json(*_args) ⇒ String
Export metrics in JSON format.
-
#to_prometheus ⇒ String
Export metrics in Prometheus format.
Constructor Details
#initialize(supervisor, sample_interval: 1.0) ⇒ PerformanceMonitor
Create a new performance monitor
39 40 41 42 43 44 45 46 47 |
# File 'lib/fractor/performance_monitor.rb', line 39 def initialize(supervisor, sample_interval: 1.0) @supervisor = supervisor @sample_interval = sample_interval @metrics = PerformanceMetricsCollector.new @start_time = nil @end_time = nil @monitoring = false @monitor_thread = nil end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
33 34 35 |
# File 'lib/fractor/performance_monitor.rb', line 33 def end_time @end_time end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
33 34 35 |
# File 'lib/fractor/performance_monitor.rb', line 33 def metrics @metrics end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
33 34 35 |
# File 'lib/fractor/performance_monitor.rb', line 33 def start_time @start_time end |
#supervisor ⇒ Object (readonly)
Returns the value of attribute supervisor.
33 34 35 |
# File 'lib/fractor/performance_monitor.rb', line 33 def supervisor @supervisor end |
Instance Method Details
#monitoring? ⇒ Boolean
Check if currently monitoring
78 79 80 |
# File 'lib/fractor/performance_monitor.rb', line 78 def monitoring? @monitoring end |
#record_job(latency, success: true) ⇒ void
This method returns an undefined value.
Record a job completion
139 140 141 |
# File 'lib/fractor/performance_monitor.rb', line 139 def record_job(latency, success: true) @metrics.record_job(latency, success: success) end |
#report ⇒ String
Generate a human-readable report
115 116 117 |
# File 'lib/fractor/performance_monitor.rb', line 115 def report PerformanceReportGenerator.generate_report(snapshot) end |
#snapshot ⇒ Hash
Get current metrics snapshot
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fractor/performance_monitor.rb', line 85 def snapshot { jobs_processed: @metrics.jobs_processed, jobs_succeeded: @metrics.jobs_succeeded, jobs_failed: @metrics.jobs_failed, average_latency: @metrics.average_latency, p50_latency: @metrics.percentile(50), p95_latency: @metrics.percentile(95), p99_latency: @metrics.percentile(99), throughput: calculate_throughput, queue_depth: current_queue_depth, queue_depth_avg: @metrics.average_queue_depth, queue_depth_max: @metrics.max_queue_depth, enqueue_rate: @metrics.enqueue_rate(uptime), dequeue_rate: @metrics.dequeue_rate(uptime), average_wait_time: @metrics.average_wait_time, p50_wait_time: @metrics.wait_time_percentile(50), p95_wait_time: @metrics.wait_time_percentile(95), p99_wait_time: @metrics.wait_time_percentile(99), worker_count: worker_count, active_workers: active_worker_count, worker_utilization: worker_utilization, memory_mb: current_memory_mb, uptime: uptime, } end |
#start ⇒ void
This method returns an undefined value.
Start monitoring
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fractor/performance_monitor.rb', line 52 def start return if @monitoring @monitoring = true @start_time = Time.now @metrics.reset # Start background monitoring thread @monitor_thread = Thread.new { monitor_loop } end |
#stop ⇒ void
This method returns an undefined value.
Stop monitoring
66 67 68 69 70 71 72 73 |
# File 'lib/fractor/performance_monitor.rb', line 66 def stop return unless @monitoring @monitoring = false @end_time = Time.now @monitor_thread&.join @monitor_thread = nil end |
#to_json(*_args) ⇒ String
Export metrics in JSON format
122 123 124 |
# File 'lib/fractor/performance_monitor.rb', line 122 def to_json(*_args) PerformanceReportGenerator.to_json(snapshot) end |
#to_prometheus ⇒ String
Export metrics in Prometheus format
129 130 131 132 |
# File 'lib/fractor/performance_monitor.rb', line 129 def to_prometheus stats = snapshot PerformanceReportGenerator.to_prometheus(stats, @metrics.total_latency) end |