rails_instrument 0.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,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rails_instrument.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,40 @@
1
+ require "rails_instrument/version"
2
+
3
+ module RailsInstrument
4
+ class Middleware
5
+ def initialize(app, options = {})
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ $rails_instrument = {}
11
+ status, headers, body = @app.call(env)
12
+ begin
13
+ headers["X-View-Runtime"] = ($rails_instrument["process_action.action_controller"][:view_runtime] / 1000).to_s
14
+ headers["X-DB-Runtime"] = ($rails_instrument["process_action.action_controller"][:db_runtime] / 1000).to_s
15
+ headers["X-DB-Query-Count"] = $rails_instrument[:sql_count].to_s
16
+ rescue
17
+ # Do nothing
18
+ end
19
+
20
+ [status, headers, body]
21
+ end
22
+ end
23
+
24
+ class Engine < ::Rails::Engine
25
+ initializer "my_engine.add_middleware" do |app|
26
+ app.middleware.use RailsInstrument::Middleware
27
+
28
+ ActiveSupport::Notifications.subscribe("process_action.action_controller") do |name, start, finish, id, payload|
29
+ $rails_instrument ||= {}
30
+ $rails_instrument[name] = payload
31
+ end
32
+
33
+ ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload|
34
+ $rails_instrument ||= {}
35
+ $rails_instrument[:sql_count] ||= 0
36
+ $rails_instrument[:sql_count] += 1 if payload[:name] != "SCHEMA"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module RailsInstrument
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rails_instrument/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rails_instrument"
7
+ s.version = RailsInstrument::VERSION
8
+ s.authors = ["Selva"]
9
+ s.email = ["k.n.selvakumar@gmail.com"]
10
+ s.homepage = "https://github.com/selvakn/rails_instrument"
11
+ s.summary = %q{Middleware to show instrumentation information in http headers}
12
+ s.description = %q{Middleware to show instrumentation information in http headers}
13
+
14
+ s.rubyforge_project = "rails_instrument"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_instrument
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Selva
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-13 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Middleware to show instrumentation information in http headers
15
+ email:
16
+ - k.n.selvakumar@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - lib/rails_instrument.rb
25
+ - lib/rails_instrument/version.rb
26
+ - rails_instrument.gemspec
27
+ homepage: https://github.com/selvakn/rails_instrument
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project: rails_instrument
47
+ rubygems_version: 1.8.6
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Middleware to show instrumentation information in http headers
51
+ test_files: []