rails-newrelic_metrics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +19 -0
- data/lib/rails/newrelic_metrics.rb +5 -0
- data/lib/rails/newrelic_metrics/api.rb +10 -0
- data/lib/rails/newrelic_metrics/unused_actions.rb +55 -0
- data/lib/rails/newrelic_metrics/version.rb +5 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6af9812052b7e39563bd7b129b2f6473d15a748c
|
4
|
+
data.tar.gz: b10659f192534fa52d464a02c9a08a8dd6b12bfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 411d49494c3e8d90c95089833200b156d43f52ad0362e6a14cb2bbf1e4d48b0546789c889f32a6ac56d01afe8e0979027ccf067311a578ab326ae6d1baeca9a9
|
7
|
+
data.tar.gz: 363f510b541ccbcc5bec38fb1f8f5729db699cf7c4fcfa06a4ccb6fab1ec7019d74170c79e90be7e9f8733270fffcd65794f86aaf7f0d432d09caea1b36229fb
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Mindaugas Mozūras
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Rails::NewRelicMetrics
|
2
|
+
|
3
|
+
Include in your Gemfile:
|
4
|
+
```ruby
|
5
|
+
group :development do
|
6
|
+
gem 'rails-newrelic_metrics'
|
7
|
+
end
|
8
|
+
```
|
9
|
+
|
10
|
+
Use from your Rails console:
|
11
|
+
```ruby
|
12
|
+
api_key = 'your New Relic API key'
|
13
|
+
app_id = 'your New Relic application id'
|
14
|
+
|
15
|
+
unused_actions = Rails::NewRelicMetrics::UnusedActions.new(api_key, app_id)
|
16
|
+
|
17
|
+
unused_actions.for(PostsController)
|
18
|
+
unused_actions.all
|
19
|
+
```
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Rails
|
2
|
+
module NewRelicMetrics
|
3
|
+
class UnusedActions < Struct.new(:api_key, :app_id)
|
4
|
+
def for(controller)
|
5
|
+
metric_names = metric_names(controller)
|
6
|
+
unused(metric_names)
|
7
|
+
end
|
8
|
+
|
9
|
+
def all
|
10
|
+
controllers.map { |controller| metric_names(controller) }
|
11
|
+
.flatten
|
12
|
+
.each_slice(100)
|
13
|
+
.map { |metric_names| unused(metric_names) }
|
14
|
+
.flatten
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def unused(metric_names)
|
20
|
+
response = call_counts(metric_names)
|
21
|
+
response.select { |metric| metric['call_count'].to_i == 0 }
|
22
|
+
.map { |metric| metric['name'][11..metric['name'].length] }
|
23
|
+
end
|
24
|
+
|
25
|
+
def call_counts(metric_names)
|
26
|
+
metrics = metric_names.map { |metric_name| "metrics[]=#{metric_name}" }.join('&')
|
27
|
+
api.json("applications/#{app_id}/data.json?#{metrics}&field=call_count&summary=1&begin=#{two_weeks_ago}&end=#{now}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def controllers
|
31
|
+
::ApplicationController.descendants
|
32
|
+
end
|
33
|
+
|
34
|
+
def api
|
35
|
+
@api ||= API.new(api_key, app_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def metric_names(controller)
|
39
|
+
controller.action_methods.map { |action| metric_name(controller, action) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def metric_name(controller, action)
|
43
|
+
"Controller/#{controller.controller_path}/#{action}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def now
|
47
|
+
Time.now.utc.iso8601
|
48
|
+
end
|
49
|
+
|
50
|
+
def two_weeks_ago
|
51
|
+
(Time.now - 60*60*24*30).utc.iso8601
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-newrelic_metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mindaugas Mozūras
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 10.1.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 10.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.14.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.14.0
|
41
|
+
description:
|
42
|
+
email: mindaugas.mozuras@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/rails/newrelic_metrics/api.rb
|
48
|
+
- lib/rails/newrelic_metrics/unused_actions.rb
|
49
|
+
- lib/rails/newrelic_metrics/version.rb
|
50
|
+
- lib/rails/newrelic_metrics.rb
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
homepage: http://github.org/mmozuras/rails-newrelic_metrics
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.3.6
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.0.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Retrieve various metrics, unused actions for your Rails app, courtesy of
|
77
|
+
NewRelic
|
78
|
+
test_files: []
|
79
|
+
has_rdoc:
|