librato-rails 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -1
- data/lib/librato/rails/aggregator.rb +11 -2
- data/lib/librato/rails/subscribers.rb +4 -4
- data/lib/librato/rails/version.rb +1 -1
- data/lib/librato/rails.rb +6 -5
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +2189 -0
- data/test/dummy/log/test.log +5250 -0
- data/test/dummy/test_env.sh +2 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CDF/870/sprockets%2Fb878faf942403e313a5b103e5d80488e +0 -0
- data/test/dummy/tmp/cache/assets/CE8/7E0/sprockets%2F178e2a1f9aa891d473009c7f3095df28 +0 -0
- data/test/dummy/tmp/cache/assets/CF9/7C0/sprockets%2F40fc2f3d2a468a00e463f1d313cb1683 +0 -0
- data/test/dummy/tmp/cache/assets/D04/890/sprockets%2F587335c079eef8d5a63784fc8f99905a +0 -0
- data/test/dummy/tmp/cache/assets/D05/D40/sprockets%2F1c9faaf28d05409b88ad3113374d613c +0 -0
- data/test/dummy/tmp/cache/assets/D11/D90/sprockets%2Ff688bee5b15ad322749fd06432065df2 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D48/6E0/sprockets%2F3d5dd928c45756c99bb1018cdbba7485 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D4F/000/sprockets%2F25e44896aac12384727e9dab827ebef9 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D66/890/sprockets%2F789354d3ec91e1ba6c8e92878d8f6ff8 +0 -0
- data/test/dummy/tmp/cache/assets/D84/000/sprockets%2F2ed60caa8412eb8334fe327cab12cb32 +0 -0
- data/test/dummy/tmp/cache/assets/D8B/F90/sprockets%2Ffe6ce696e9141eb755d8eed79128e17c +0 -0
- data/test/dummy/tmp/cache/assets/D98/8B0/sprockets%2Fedbef6e0d0a4742346cf479f2c522eb0 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/fixtures/config/librato.yml +1 -0
- data/test/integration/mail_test.rb +1 -3
- data/test/integration/request_test.rb +14 -18
- data/test/integration/sql_test.rb +8 -10
- data/test/metrics-rails_test.rb +5 -0
- data/test/unit/aggregator_test.rb +29 -6
- data/test/unit/configuration_test.rb +5 -3
- metadata +223 -183
    
        data/README.md
    CHANGED
    
    | @@ -7,7 +7,9 @@ Report key statistics for your Rails app to [Librato Metrics](https://metrics.li | |
| 7 7 |  | 
| 8 8 | 
             
            **NOTE: This is currently in alpha development and is not yet officially supported**
         | 
| 9 9 |  | 
| 10 | 
            -
            ** | 
| 10 | 
            +
            **NOTES FOR ALPHA TESTERS:**
         | 
| 11 | 
            +
             * If you are upgrading from a version prior to the rename to librato-rails, note that *the env variable names for configuration and the name of the config files have changed*. See the new names in configuration, below.
         | 
| 12 | 
            +
             * Starting with 0.4.0 *all metrics are now submitted as gauges*. If you were using a prior version you will need to manually remove any librato-rails generated metrics which are counters.
         | 
| 11 13 |  | 
| 12 14 | 
             
            ## Installation
         | 
| 13 15 |  | 
| @@ -36,10 +36,19 @@ module Librato | |
| 36 36 | 
             
                    queue.merge!(queued) if queued
         | 
| 37 37 | 
             
                  end
         | 
| 38 38 |  | 
| 39 | 
            -
                  def measure( | 
| 39 | 
            +
                  def measure(*args, &block)
         | 
| 40 | 
            +
                    event = args[0].to_s
         | 
| 41 | 
            +
                    returned = nil
         | 
| 40 42 | 
             
                    @lock.synchronize do
         | 
| 41 | 
            -
                       | 
| 43 | 
            +
                      if block_given?
         | 
| 44 | 
            +
                        start = Time.now
         | 
| 45 | 
            +
                        returned = yield
         | 
| 46 | 
            +
                        @cache.add event => ((Time.now - start) * 1000.0).to_i
         | 
| 47 | 
            +
                      else
         | 
| 48 | 
            +
                        @cache.add event => args[1] || nil
         | 
| 49 | 
            +
                      end
         | 
| 42 50 | 
             
                    end
         | 
| 51 | 
            +
                    returned
         | 
| 43 52 | 
             
                  end
         | 
| 44 53 | 
             
                  alias :timing :measure
         | 
| 45 54 |  | 
| @@ -15,7 +15,7 @@ module Librato | |
| 15 15 | 
             
                  exception = event.payload[:exception]
         | 
| 16 16 | 
             
                  # page_key = "request.#{controller}.#{action}_#{format}."
         | 
| 17 17 |  | 
| 18 | 
            -
                  group " | 
| 18 | 
            +
                  group "rails.request" do |r|
         | 
| 19 19 |  | 
| 20 20 | 
             
                    r.increment 'total'
         | 
| 21 21 | 
             
                    r.timing    'time', event.duration
         | 
| @@ -46,7 +46,7 @@ module Librato | |
| 46 46 | 
             
                ActiveSupport::Notifications.subscribe 'sql.active_record' do |*args|
         | 
| 47 47 | 
             
                  payload = args.last
         | 
| 48 48 |  | 
| 49 | 
            -
                  group " | 
| 49 | 
            +
                  group "rails.sql" do |s|
         | 
| 50 50 | 
             
                    # puts (event.payload[:name] || 'nil') + ":" + event.payload[:sql] + "\n"
         | 
| 51 51 | 
             
                    s.increment 'queries'
         | 
| 52 52 |  | 
| @@ -62,13 +62,13 @@ module Librato | |
| 62 62 |  | 
| 63 63 | 
             
                ActiveSupport::Notifications.subscribe 'deliver.action_mailer' do |*args|
         | 
| 64 64 | 
             
                  # payload[:mailer] => 'UserMailer'
         | 
| 65 | 
            -
                  group " | 
| 65 | 
            +
                  group "rails.mail" do |m|
         | 
| 66 66 | 
             
                    m.increment 'sent'
         | 
| 67 67 | 
             
                  end
         | 
| 68 68 | 
             
                end
         | 
| 69 69 |  | 
| 70 70 | 
             
                ActiveSupport::Notifications.subscribe 'receive.action_mailer' do |*args|
         | 
| 71 | 
            -
                  group " | 
| 71 | 
            +
                  group "rails.mail" do |m|
         | 
| 72 72 | 
             
                    m.increment 'received'
         | 
| 73 73 | 
             
                  end
         | 
| 74 74 | 
             
                end
         | 
    
        data/lib/librato/rails.rb
    CHANGED
    
    | @@ -19,7 +19,7 @@ module Librato | |
| 19 19 |  | 
| 20 20 | 
             
              module Rails
         | 
| 21 21 | 
             
                extend SingleForwardable
         | 
| 22 | 
            -
                CONFIG_SETTABLE = %w{user token flush_interval prefix source}
         | 
| 22 | 
            +
                CONFIG_SETTABLE = %w{user token flush_interval prefix source source_pids}
         | 
| 23 23 | 
             
                FORKING_SERVERS = [:unicorn, :passenger]
         | 
| 24 24 |  | 
| 25 25 | 
             
                mattr_accessor :config_file
         | 
| @@ -30,10 +30,11 @@ module Librato | |
| 30 30 | 
             
                mattr_accessor :token
         | 
| 31 31 | 
             
                mattr_accessor :flush_interval
         | 
| 32 32 | 
             
                mattr_accessor :prefix
         | 
| 33 | 
            +
                mattr_accessor :source_pids
         | 
| 33 34 |  | 
| 34 35 | 
             
                # config defaults
         | 
| 35 36 | 
             
                self.flush_interval = 60 # seconds
         | 
| 36 | 
            -
                self. | 
| 37 | 
            +
                self.source_pids = true
         | 
| 37 38 |  | 
| 38 39 | 
             
                def_delegators :counters, :increment
         | 
| 39 40 | 
             
                def_delegators :aggregate, :measure, :timing
         | 
| @@ -66,7 +67,7 @@ module Librato | |
| 66 67 | 
             
                      logger.debug "[librato-rails] no configuration file present, using ENV variables"
         | 
| 67 68 | 
             
                      self.token = ENV['LIBRATO_METRICS_TOKEN'] if ENV['LIBRATO_METRICS_TOKEN']
         | 
| 68 69 | 
             
                      self.user = ENV['LIBRATO_METRICS_USER'] if ENV['LIBRATO_METRICS_USER']
         | 
| 69 | 
            -
                      self. | 
| 70 | 
            +
                      self.source = ENV['LIBRATO_METRICS_SOURCE'] if ENV['LIBRATO_METRICS_SOURCE']
         | 
| 70 71 | 
             
                    end
         | 
| 71 72 | 
             
                  end
         | 
| 72 73 |  | 
| @@ -94,7 +95,7 @@ module Librato | |
| 94 95 | 
             
                  # send all current data to Metrics
         | 
| 95 96 | 
             
                  def flush
         | 
| 96 97 | 
             
                    logger.debug "[librato-rails] flushing #{Process.pid} (#{Time.now}):"
         | 
| 97 | 
            -
                    queue = client.new_queue(:source => qualified_source)
         | 
| 98 | 
            +
                    queue = client.new_queue(:source => qualified_source, :prefix => self.prefix)
         | 
| 98 99 | 
             
                    # thread safety is handled internally for both stores
         | 
| 99 100 | 
             
                    counters.flush_to(queue)
         | 
| 100 101 | 
             
                    aggregate.flush_to(queue)
         | 
| @@ -115,7 +116,7 @@ module Librato | |
| 115 116 |  | 
| 116 117 | 
             
                  # source including process pid
         | 
| 117 118 | 
             
                  def qualified_source
         | 
| 118 | 
            -
                    "#{source}.#{$$}"
         | 
| 119 | 
            +
                    self.source_pids ? "#{source}.#{$$}" : source
         | 
| 119 120 | 
             
                  end
         | 
| 120 121 |  | 
| 121 122 | 
             
                  # run once during Rails startup sequence
         | 
| 
            File without changes
         | 
| Binary file |