moped-rails-instrumentation 0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tom Ward
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,14 @@
1
+ Moped Rails 3 Instrumentation
2
+ =============================
3
+
4
+ Records how long your rails app spends in Mongo (via Moped), and outputs it to the log, i.e.:
5
+
6
+ Completed 200 OK in 1535ms (Views: 623.3ms | Mongo: 848.2ms)
7
+
8
+ To use, just add the gem to your Gemfile and restart your app:
9
+
10
+ gem 'moped-rails-instrumentation', '~>0.1'
11
+
12
+ It's been tested with rails 3.0, and should work with rails 3.1 too.
13
+
14
+ This gem is based on mongo-rails-instrumentation by Tom Ward, available at https://github.com/freerange/mongo-rails-instrumentation and then ported to Moped by Stan Mazurek at https://github.com/stan/mongo-rails-instrumentation. It is released here by me only to provide a gem.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
1
+ require 'moped/rails/instrumentation/railtie'
@@ -0,0 +1,10 @@
1
+ module Moped
2
+ module Rails
3
+ module Instrumentation
4
+ autoload :Version, 'moped/rails/instrumentation/version'
5
+ autoload :Railtie, 'moped/rails/instrumentation/railtie'
6
+ autoload :LogSubscriber, 'moped/rails/instrumentation/log_subscriber'
7
+ autoload :ControllerRuntime, 'moped/rails/instrumentation/controller_runtime'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ require 'moped/rails/instrumentation'
2
+
3
+ module Moped::Rails::Instrumentation
4
+ module ControllerRuntime
5
+ extend ActiveSupport::Concern
6
+
7
+ protected
8
+
9
+ attr_internal :mongo_runtime
10
+
11
+ def process_action(action, *args)
12
+ LogSubscriber.reset_runtime
13
+ super
14
+ end
15
+
16
+ def cleanup_view_runtime
17
+ mongo_rt_before_render = LogSubscriber.reset_runtime
18
+ runtime = super
19
+ mongo_rt_after_render = LogSubscriber.reset_runtime
20
+ self.mongo_runtime = mongo_rt_before_render + mongo_rt_after_render
21
+ runtime - mongo_rt_after_render
22
+ end
23
+
24
+ def append_info_to_payload(payload)
25
+ super
26
+ payload[:mongo_runtime] = mongo_runtime
27
+ end
28
+
29
+ module ClassMethods
30
+ def log_process_action(payload)
31
+ messages, mongo_runtime = super, payload[:mongo_runtime]
32
+ messages << ("Mongo: %.1fms" % mongo_runtime.to_f) if mongo_runtime
33
+ messages
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ require 'moped/rails/instrumentation'
2
+
3
+ class Moped::Rails::Instrumentation::LogSubscriber < ActiveSupport::LogSubscriber
4
+ RUNTIME_KEY = name + "#runtime"
5
+ COUNT_KEY = name + "#count"
6
+
7
+ def self.runtime=(value)
8
+ Thread.current[RUNTIME_KEY] = value
9
+ end
10
+
11
+ def self.runtime
12
+ Thread.current[RUNTIME_KEY] ||= 0
13
+ end
14
+
15
+ def self.count=(value)
16
+ Thread.current[COUNT_KEY] = value
17
+ end
18
+
19
+ def self.count
20
+ Thread.current[COUNT_KEY] ||= 0
21
+ end
22
+
23
+ def self.reset_runtime
24
+ rt, self.runtime, self.count = runtime, 0, 0
25
+ rt
26
+ end
27
+
28
+ def mongo(event)
29
+ self.class.runtime += event.duration
30
+ self.class.count += 1
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ require 'moped/rails/instrumentation'
2
+
3
+ module Moped::Rails::Instrumentation
4
+ class Railtie < Rails::Railtie
5
+ initializer "moped.rails.instrumentation" do |app|
6
+ instrument Moped::Connection, [
7
+ :read,
8
+ :write
9
+ ]
10
+
11
+ ActiveSupport.on_load(:action_controller) do
12
+ include ControllerRuntime
13
+ end
14
+
15
+ LogSubscriber.attach_to :moped
16
+ end
17
+
18
+ def instrument(clazz, methods)
19
+ clazz.module_eval do
20
+ methods.each do |m|
21
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
22
+ def #{m}_with_instrumentation(*args, &block)
23
+ ActiveSupport::Notifications.instrumenter.instrument "mongo.mongo", :name => "#{m}" do
24
+ #{m}_without_instrumentation(*args, &block)
25
+ end
26
+ end
27
+ CODE
28
+
29
+ alias_method_chain m, :instrumentation
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ module Moped
2
+ module Rails
3
+ module Instrumentation
4
+ VERSION = '0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "moped/rails/instrumentation/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "moped-rails-instrumentation"
7
+ s.version = Moped::Rails::Instrumentation::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jason Coene"]
10
+ s.email = ["jcoene@gmail.com"]
11
+ s.homepage = "http://github.com/jcoene/moped-rails-instrumentation"
12
+ s.summary = %q{Records time spent in Moped for mongo and adds to request logs.}
13
+ s.description = %q{Records time spent in Moped for mongo and adds to request logs.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moped-rails-instrumentation
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Coene
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Records time spent in Moped for mongo and adds to request logs.
15
+ email:
16
+ - jcoene@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - MIT-LICENSE
24
+ - README
25
+ - Rakefile
26
+ - lib/moped-rails-instrumentation.rb
27
+ - lib/moped/rails/instrumentation.rb
28
+ - lib/moped/rails/instrumentation/controller_runtime.rb
29
+ - lib/moped/rails/instrumentation/log_subscriber.rb
30
+ - lib/moped/rails/instrumentation/railtie.rb
31
+ - lib/moped/rails/instrumentation/version.rb
32
+ - moped-rails-instrumentation.gemspec
33
+ homepage: http://github.com/jcoene/moped-rails-instrumentation
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.23
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Records time spent in Moped for mongo and adds to request logs.
57
+ test_files: []