GC Reporter
A simple Rails extension to collect and report Garbage Collection (GC.stat
) and ObjectSpace
statistics from your Ruby applications to a central monitoring application via Action Cable.
It is designed to be lightweight and work in various Ruby process types:
- Rails servers (Puma, Unicorn, etc.)
- Sidekiq workers
- Rake tasks
Receiving Application Setup
Before using this gem, you need a Rails application with an Action Cable channel ready to receive the data.
Generate a channel:
rails g channel GcStats
Implement the channel: The channel needs to define a
report
action, which is the remote procedure call (RPC) endpoint this gem uses.# app/channels/gc_stats_channel.rb class GcStatsChannel < ApplicationCable::Channel def subscribed stream_from "gc_stats_channel" end def unsubscribed # Any cleanup needed when a client disconnects end # This is the action called by the gem's client. def report(data) # data is the payload sent from the gc_reporter gem. # Process it here: log it, save to a DB, or broadcast to a live dashboard. Rails.logger.info "Received GC Stats from #{data['source']} (PID: #{data['process_id']})" # Example: Broadcast to a UI dashboard ActionCable.server.broadcast("live_dashboard_channel", data) end end
Installation
Add gc_reporter
to your application's Gemfile.
# Gemfile
gem 'gc_reporter', git: '[https://github.com/example/gc_reporter](https://github.com/example/gc_reporter)' # Or from RubyGems when published