basecamp/trashed

Name: trashed

Owner: Basecamp

Description: Tell StatsD about request time, GC, objects and more. Latest Rails 4 and Ruby 2.1 support, and ancient Rails 2 and Ruby 1.8 support.

Created: 2009-08-25 01:39:34.0

Updated: 2018-03-07 05:33:26.0

Pushed: 2017-11-08 16:45:00.0

Homepage:

Size: 66

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Trashed

Keep an eye on resource usage.

Setup
Rails 5

On Rails 5 (and Rails 3 and 4), add this to the top of config/application.rb:

require 'trashed/railtie'

And in the body of your app config:

module YourApp
  class Application < Rails::Application
    config.trashed.statsd = YourApp.statsd
Rails 2

On Rails 2, add the middleware to config/environment.rb:

Rails::Initializer.run do |config|
  reporter = Trashed::Reporter.new
  reporter.logger = Rails.logger
  reporter.statsd = YourApp.statsd

  config.middleware.use Trashed::Rack, reporter
end
Custom dimensions

You probably want stats per controller, action, right?

Set a #timing_dimensions lambda to return a list of dimensions to qualify per-request measurements like time elapsed, GC time, objects allocated, etc.

For example:

ig.trashed.timing_dimensions = ->(env) do
Rails 3, 4, and 5, set this. Other Rack endpoints won't have it.
 controller = env['action_controller.instance']
name    = controller.controller_name
action  = controller.action_name
format  = controller.rendered_format || :none
variant = controller.request.variant || :none  # Rails 4.1+ only!

[ :All,
  :"Controllers.#{name}",
  :"Actions.#{name}.#{action}.#{format}+#{variant}" ]
d

Results in metrics like:

Namespace.All.Time.wall
Namespace.Controllers.SessionsController.Time.wall
Namespace.Actions.SessionsController.index.json+phone.Time.wall

Similarly, set a #gauge_dimensions lambda to return a list of dimensions to qualify measurements which gauge current state, like heap slots used or total number of live String objects.

For example:

ig.trashed.gauge_dimensions = ->(env) {
:All,
:"Stage.#{Rails.env}",
:"Hosts.#{`hostname -s`.chomp}" ]

Results in metrics like:

Namespace.All.Objects.T_STRING
Namespace.Stage.production.Objects.T_STRING
Namespace.Hosts.host-001.Objects.T_STRING
Version history

3.2.7 (November 8, 2017)

3.2.6 (June 21, 2017)

3.2.5 (Feb 26, 2015)

3.2.4 (July 25, 2014)

3.2.3 (June 23, 2014)

3.2.2 (March 31, 2014)

3.1.0 (March 30, 2014)

3.0.1 (March 30, 2014)

3.0.0 (March 29, 2014)

2.0.5 (December 15, 2012)

2.0.0 (December 1, 2011)

1.0.0 (August 24, 2009)


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.