Class: NatsWork::Monitoring::SystemMetrics
- Inherits:
-
Object
- Object
- NatsWork::Monitoring::SystemMetrics
- Defined in:
- lib/natswork/monitoring.rb
Overview
Built-in system metrics collector
Instance Method Summary collapse
-
#initialize(metrics = nil) ⇒ SystemMetrics
constructor
A new instance of SystemMetrics.
- #start_collection(interval = 30) ⇒ Object
- #stop_collection ⇒ Object
Constructor Details
#initialize(metrics = nil) ⇒ SystemMetrics
Returns a new instance of SystemMetrics.
354 355 356 357 |
# File 'lib/natswork/monitoring.rb', line 354 def initialize(metrics = nil) @metrics = metrics || Metrics.global @enabled = false end |
Instance Method Details
#start_collection(interval = 30) ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/natswork/monitoring.rb', line 359 def start_collection(interval = 30) return if @enabled @enabled = true @collection_thread = Thread.new do while @enabled collect_system_metrics sleep interval end end end |
#stop_collection ⇒ Object
371 372 373 374 |
# File 'lib/natswork/monitoring.rb', line 371 def stop_collection @enabled = false @collection_thread&.join end |