Skip to content

Instantly share code, notes, and snippets.

@johnhamelink
Created April 1, 2015 09:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhamelink/cbef04581da5c3dd90be to your computer and use it in GitHub Desktop.
Save johnhamelink/cbef04581da5c3dd90be to your computer and use it in GitHub Desktop.
require 'statsd'
class RackGcHeapInstrumentation
def initialize(app)
@app = app
@statsd = Statsd.new('localhost', 8125)
end
def call(env)
GC.enable # Ensure garbage colletion is enabled
ret = @app.call(env)
@statsd.gauge('api.heap.live_slots', GC.stat[:heap_live_slots].to_i, sample_rate: 0.5, tags: ['process:rails'])
return ret
end
end
@johnhamelink
Copy link
Author

Usage:

In your config.ru:

require ::File.expand_path('../lib/rack_gc_heap_instrumentation', __FILE__)
use RackGcHeapInstrumentation
run Rails.application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment