• Stars
    star
    189
  • Rank 197,307 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

Trashed

Keep an eye on resource usage.

  • Sends per-request object counts, heap growth, GC time, and more to StatsD.
  • Sends snapshots of resource usage, e.g. live String objects, to StatsD.
  • Supports new stuff: Rails 5.1 and latest Ruby 2.x features.
  • Supports old stuff: Rails 2/3/4, Ruby 1.9+, REE, Ruby 1.8 with RubyBench patches.

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:

config.trashed.timing_dimensions = ->(env) do
  # Rails 3, 4, and 5, set this. Other Rack endpoints won't have it.
  if 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}" ]
  end
end

Results in metrics like:

YourNamespace.All.Time.wall
YourNamespace.Controllers.SessionsController.Time.wall
YourNamespace.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:

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

Results in metrics like:

YourNamespace.All.Objects.T_STRING
YourNamespace.Stage.production.Objects.T_STRING
YourNamespace.Hosts.host-001.Objects.T_STRING

Version history

3.2.8 (January 31, 2022)

  • REE: Fix that GC.time is reported in microseconds instead of milliseconds

3.2.7 (November 8, 2017)

  • Ruby 1.8.7 compatibility

3.2.6 (June 21, 2017)

  • Mention Rails 5 support

3.2.5 (Feb 26, 2015)

  • Support Ruby 2.2 GC.stat naming, avoiding 2.1 warnings

3.2.4 (July 25, 2014)

  • Fix compatibility with Rails 3.x tagged logging - @calavera

3.2.3 (June 23, 2014)

  • Report CPU/Idle time in tenths of a percent

3.2.2 (March 31, 2014)

  • Reduce default sampling rates.
  • Stop gauging all GC::Profiler data. Too noisy.
  • Report gauge readings as StatsD timings.
  • Support providing a Statsd::Batch since using Statsd#batch results in underfilled packets at low sample rates.
  • Fix bug with sending arrays of timings to StatsD.
  • Record GC timings in milliseconds.

3.1.0 (March 30, 2014)

  • Report percent CPU/idle time: Time.pct.cpu and Time.pct.idle.
  • Measure out-of-band GC count, time, and stats. Only meaningful for single-threaded servers like Unicorn. But then again so is per-request GC monitoring.
  • Support @tmm1's GC::OOB (https://github.com/tmm1/gctools).
  • Measure time between GCs.
  • Spiff up logger reports with more timings.
  • Support Rails log tags on logged reports.
  • Allow instruments' #start to set timings/gauges.

3.0.1 (March 30, 2014)

  • Sample requests to instrument based on StatsD sample rate.

3.0.0 (March 29, 2014)

  • Support new Ruby 2.0 and 2.1 GC stats.
  • Gauge GC details with GC::Profiler.
  • Performance rework. Faster, fewer allocations.
  • Rework counters and gauges as instruments.
  • Batch StatsD messages to decrease overhead on the server.
  • Drop NewRelic samplers.

2.0.5 (December 15, 2012)

  • Relax outdated statsd-ruby dependency.

2.0.0 (December 1, 2011)

  • Rails 3 support.
  • NewRelic samplers.

1.0.0 (August 24, 2009)

  • Initial release.

More Repositories

1

trix

A rich text editor for everyday writing
JavaScript
17,847
star
2

kamal

Deploy web apps anywhere.
Ruby
8,744
star
3

handbook

Basecamp Employee Handbook
6,165
star
4

pow

Zero-configuration Rack server for Mac OS X
CoffeeScript
3,423
star
5

policies

37signals policies, terms, and legal. Share them; reuse them; contribute to them.
1,863
star
6

local_time

Rails engine for cache-friendly, client-side local time
CoffeeScript
1,791
star
7

marginalia

Attach comments to ActiveRecord's SQL queries
Ruby
1,676
star
8

mail_view

Visual email testing
Ruby
1,341
star
9

xip-pdns

PowerDNS pipe backend adapter powering xip.io
Shell
1,159
star
10

geared_pagination

Paginate Active Record sets at variable speeds
Ruby
758
star
11

wysihat

A WYSIWYG JavaScript framework
JavaScript
681
star
12

bcx-api

API documentation and wrappers for Basecamp 2
672
star
13

name_of_person

Presenting names of people in full, familiar, abbreviated, and initialized forms (but without titulation etc)
Ruby
647
star
14

console1984

The Rails console you love, 1984 style
Ruby
548
star
15

google_sign_in

Sign in (or up) with Google for Rails applications
Ruby
494
star
16

bc3-api

API documentation for Basecamp 4
472
star
17

intermission

intermission helps you perform zero down time application maintenance
Lua
364
star
18

snapback_cache

A client side page cache for jquery.
JavaScript
316
star
19

audits1984

Auditing tool for Rails console sessions
Ruby
309
star
20

full_request_logger

Make full request logs accessible via web UI
Ruby
305
star
21

mysql_role_swap

(Nearly) Zero interruption mysql maintenance script.
Ruby
282
star
22

mission_control-jobs

Dashboard and Active Job extensions to operate and troubleshoot background jobs
Ruby
270
star
23

concerning

Bite-sized separation of concerns
Ruby
201
star
24

api

API integration and more for Basecamp products (Basecamp, Highrise, Campfire, Backpack)
192
star
25

easymon

Easy Monitoring
Ruby
191
star
26

highrise-api

Official API documentation for Highrise
130
star
27

fast_remote_cache

A faster version of Capistrano's remote_cache deployment strategy
Ruby
125
star
28

mass_encryption

Ruby
104
star
29

platform_agent

Parse user agent to deduce the platform
Ruby
103
star
30

cached_externals

Symlink to external dependencies, rather than bloating your repositories with them
Ruby
100
star
31

campfire-api

Official API documentation for Campfire
97
star
32

basecamp-classic-api

Official API documentation for Basecamp Classic
87
star
33

lufo

Tracks the most recent options chosen on a `<select>` element and displays them at the top of the list
JavaScript
87
star
34

powprox

Pow .dev sites, meet SSL and HTTP/2
Shell
83
star
35

libmemcached_store

ActiveSupport::Cache wrapper for libmemcached
Ruby
81
star
36

action_profiler

Profile Rails requests on a live app
Ruby
75
star
37

bc3-integrations

Ruby
73
star
38

project_search

Rails plugin that adds a script/find command for searching your project
Ruby
71
star
39

activestorage-office-previewer

Active Storage previewer for Microsoft Office files based on LibreOffice
Ruby
67
star
40

dumpsterfire-2020

Code that runs the dumpster
HTML
47
star
41

turbo-8-morphing-demo

Ruby
43
star
42

cognition

Match text; run commands. Works great for building a chatbot!
Ruby
37
star
43

snapshot

A rails plugin that provides tasks for creating and restoring snapshots of development data.
Ruby
34
star
44

backpack-api

Official API documentation for Backpack
Ruby
20
star
45

ruby-dev

Old Rubies on new Macs
15
star
46

orc

Orc(hestrator) - A really bad pow.cx clone for linux
Shell
10
star
47

cleversafe

Ruby
7
star
48

memcached_bench

Ruby
6
star
49

duo-api

Ruby Gem for communicating with the Duo Api
Ruby
6
star
50

accessibility

Guidelines and tools we use at 37signals to make sure our apps are accessible
5
star
51

Xamarin.iOS.OnePasswordExtension

1Password bindings for Xamarin.iOS
C#
5
star
52

mail

Ruby
4
star
53

composed_of_ipaddr

Compact IPv4 attributes for Active Record. Presents an unsigned int (4 bytes) as an IPAddr.
Ruby
4
star
54

house-style

37signals house style
Ruby
3
star
55

deep_hash_transform

Re-key a nested Hash to all-Symbol or -String keys. Rails 4+ backport.
Ruby
3
star
56

github-issues

Github Issue query CLI
Go
2
star
57

homebrew-dev

Old software to build old stuff on new Macs
Ruby
1
star
58

nsone

A stupid simple API client for NS1
Ruby
1
star