newrelic_moped-toothrot 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/lib/newrelic_moped.rb +2 -0
- data/lib/newrelic_moped/instrumentation.rb +80 -0
- data/lib/newrelic_moped/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d80de88fba1c69e6e1067cc6c7ec31426235b85b
|
4
|
+
data.tar.gz: e00836953a8e1006d9666f4061f731f7e63dad8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4561c43947b349d62b90c86f654417583cba22aa5a26e6947f8ba3a9921bf57d276686cdeb299db0e5d854ce29dc462319504b8af77823a63ea2554190475d24
|
7
|
+
data.tar.gz: 11f60daece4d59f4ec1f20078734675961ad4d321568d4102866a434da134107564ba82ced40f81170f6b5b43c582183678bdbb4dc6cab125b175904a6dabed0
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Stephen Bartholomew
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# New Relic Moped
|
2
|
+
|
3
|
+
New Relic instrumentation for Moped / Mongoid 3
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'newrelic_moped'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install newrelic_moped
|
18
|
+
|
19
|
+
## News
|
20
|
+
|
21
|
+
There's no official place for news & updates yet but you can follow @sbartholomew on Twitter for announcements.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'new_relic/agent/method_tracer'
|
2
|
+
|
3
|
+
DependencyDetection.defer do
|
4
|
+
@name = :moped
|
5
|
+
|
6
|
+
depends_on do
|
7
|
+
defined?(::Moped) && !NewRelic::Control.instance['disable_moped']
|
8
|
+
end
|
9
|
+
|
10
|
+
executes do
|
11
|
+
NewRelic::Agent.logger.info 'Installing Moped instrumentation'
|
12
|
+
end
|
13
|
+
|
14
|
+
executes do
|
15
|
+
Moped::Node.class_eval do
|
16
|
+
include NewRelic::Moped::Instrumentation
|
17
|
+
alias_method :logging_without_newrelic_trace, :logging
|
18
|
+
alias_method :logging, :logging_with_newrelic_trace
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module NewRelic
|
24
|
+
module Moped
|
25
|
+
module Instrumentation
|
26
|
+
def logging_with_newrelic_trace(operations, &blk)
|
27
|
+
operation_name, collection = determine_operation_and_collection(operations.first)
|
28
|
+
log_statement = operations.first.log_inspect.encode("UTF-8")
|
29
|
+
|
30
|
+
metric = case operation_name
|
31
|
+
when 'INSERT', 'UPDATE', 'CREATE' then 'save'
|
32
|
+
when 'QUERY', 'COUNT' then 'find'
|
33
|
+
when 'DELETE' then 'destroy'
|
34
|
+
else
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
command = Proc.new { logging_without_newrelic_trace(operations, &blk) }
|
39
|
+
res = nil
|
40
|
+
|
41
|
+
if metric
|
42
|
+
metrics = ["ActiveRecord/#{collection}/#{operation_name}","ActiveRecord/all"]
|
43
|
+
|
44
|
+
self.class.trace_execution_scoped(metrics) do
|
45
|
+
t0 = Time.now
|
46
|
+
begin
|
47
|
+
res = command.call
|
48
|
+
ensure
|
49
|
+
elapsed_time = (Time.now - t0).to_f
|
50
|
+
|
51
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(log_statement, nil, elapsed_time)
|
52
|
+
NewRelic::Agent.instance.sql_sampler.notice_sql(log_statement, metric, nil, elapsed_time)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
res = command.call
|
57
|
+
end
|
58
|
+
|
59
|
+
res
|
60
|
+
end
|
61
|
+
|
62
|
+
def determine_operation_and_collection(operation)
|
63
|
+
log_statement = operation.log_inspect.encode("UTF-8")
|
64
|
+
collection = "Unknown"
|
65
|
+
if operation.respond_to?(:collection)
|
66
|
+
collection = operation.collection
|
67
|
+
end
|
68
|
+
operation_name = log_statement.split[0]
|
69
|
+
if operation_name == 'COMMAND' && log_statement.include?(":mapreduce")
|
70
|
+
operation_name = 'MAPREDUCE'
|
71
|
+
collection = log_statement[/:mapreduce=>"([^"]+)/,1]
|
72
|
+
elsif operation_name == 'COMMAND' && log_statement.include?(":count")
|
73
|
+
operation_name = 'COUNT'
|
74
|
+
collection = log_statement[/:count=>"([^"]+)/,1]
|
75
|
+
end
|
76
|
+
return operation_name, collection
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic_moped-toothrot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Bartholomew
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: newrelic_rpm
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: moped
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: New Relic Instrumentation for Moped & Mongoid 3
|
56
|
+
email:
|
57
|
+
- stephenbartholomew@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/newrelic_moped/instrumentation.rb
|
63
|
+
- lib/newrelic_moped/version.rb
|
64
|
+
- lib/newrelic_moped.rb
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
homepage: ''
|
68
|
+
licenses: []
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.0.3
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: New Relic Instrumentation for Moped & Mongoid 3
|
90
|
+
test_files: []
|