Sha256: a6e26057e70c1244a4bb72c860659d41d605ad28d3386e690675d047ceb04180

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

class Async::App::Metrics::RubyRuntimeMetricsCollector
  include Async::App::TimerComponent
  include Async::App::AutoloadComponent

  def on_tick = bus.publish("metrics.updated", metrics)
  def interval = 5
  def run_on_start = true
  def on_error(exception) = warn { exception }

  private

  def metrics
    fibers = ObjectSpace.each_object(Fiber)
    threads = ObjectSpace.each_object(Thread)
    ractors = ObjectSpace.each_object(Ractor)
    {
      ruby_fibers: { value: fibers.count },
      ruby_fibers_active: { value: fibers.count(&:alive?) },
      ruby_threads: { value: threads.count },
      ruby_threads_active: { value: threads.count(&:alive?) },
      ruby_ractors: { value: ractors.count },
      ruby_memory: { value: GetProcessMem.new.bytes.to_s("F"), suffix: "bytes" }
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
async-tools-0.2.10 lib/async/app/metrics/ruby_runtime_metrics_collector.rb