evil-metrics-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +46 -0
- data/.travis.yml +5 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +8 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/evil-metrics-rails.gemspec +27 -0
- data/lib/evil/metrics/rails.rb +63 -0
- data/lib/evil/metrics/rails/railtie.rb +15 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d75ebdeb80b6ee5637aceb7f500673c90f576c47224c8fabcf539a8667e332fc
|
4
|
+
data.tar.gz: a337c39163c2ec9bb552a4ffdd573da6e3ea485cf942d075d9f4f1ce229c6830
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d50151f035cb14b2c0cce74dab0050b5a3a03986ca1fc7e70e82957330c4a4340ab92a0836dab61bf9255fbe6deedabb36520db9ba90fe598fef0f114ea57b4a
|
7
|
+
data.tar.gz: 478cec02f1e03bea1ee3709472f86693d34531da48632b97c0cf4d30f54da52657dc7e470a8b18d737d99226b4d13b2a7b5baeb633e69f5bd410290c2ff2b675
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
require:
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.3
|
7
|
+
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Exclude:
|
10
|
+
- "Gemfile"
|
11
|
+
- "spec/**/*"
|
12
|
+
|
13
|
+
Style/BracesAroundHashParameters:
|
14
|
+
EnforcedStyle: context_dependent
|
15
|
+
|
16
|
+
Style/StringLiterals:
|
17
|
+
EnforcedStyle: double_quotes
|
18
|
+
|
19
|
+
# Allow to use let!
|
20
|
+
RSpec/LetSetup:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
RSpec/MultipleExpectations:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Bundler/OrderedGems:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/TrailingCommaInArguments:
|
30
|
+
Description: 'Checks for trailing comma in argument lists.'
|
31
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma'
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyleForMultiline: consistent_comma
|
34
|
+
|
35
|
+
Style/TrailingCommaInArrayLiteral:
|
36
|
+
Description: 'Checks for trailing comma in array literals.'
|
37
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
38
|
+
Enabled: true
|
39
|
+
EnforcedStyleForMultiline: consistent_comma
|
40
|
+
|
41
|
+
Style/TrailingCommaInHashLiteral:
|
42
|
+
Description: 'Checks for trailing comma in hash literals.'
|
43
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
44
|
+
Enabled: true
|
45
|
+
EnforcedStyleForMultiline: consistent_comma
|
46
|
+
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in evil-metrics-rails.gemspec
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem "pry"
|
12
|
+
gem "pry-byebug", platform: :mri
|
13
|
+
|
14
|
+
gem "rubocop"
|
15
|
+
gem "rubocop-rspec"
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Andrey Novikov
|
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,55 @@
|
|
1
|
+
# Evil::Metrics::[Rails]
|
2
|
+
|
3
|
+
Built-in metrics for out-of-the box [Rails] applications monitoring
|
4
|
+
|
5
|
+
if your monitoring system already collects Rails metrics (e.g. NewRelic) then you don't need this gem.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'evil-metrics-rails'
|
13
|
+
# Then add monitoring system adapter, e.g.:
|
14
|
+
# gem 'evil-metrics-prometheus'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Metrics
|
22
|
+
|
23
|
+
- Total web requests received: `rails_requests_total`
|
24
|
+
- Web request duration: `rails_request_duration` (in seconds)
|
25
|
+
- Views rendering duration: `rails_view_runtime` (in seconds)
|
26
|
+
- DB request duration: `rails_db_runtime` (in seconds)
|
27
|
+
|
28
|
+
|
29
|
+
## Hooks
|
30
|
+
|
31
|
+
- `on_controller_action`: Allows to collect
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Evil::Metrics::Rails.on_controller_action do |event, labels|
|
35
|
+
next unless event.payload[:ext_service_runtime]
|
36
|
+
time_in_seconds = event.payload[:ext_service_runtime] / 1000.0
|
37
|
+
rails_ext_service_runtime.measure(labels, time_in_seconds)
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/evil-metrics/evil-metrics-rails.
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
|
+
|
55
|
+
[Rails]: https://rubyonrails.org "Ruby on Rails MVC web-application framework optimized for programmer happiness"
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "evil/metrics/rails"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "evil-metrics-rails"
|
5
|
+
spec.version = "0.1.0"
|
6
|
+
spec.authors = ["Andrey Novikov"]
|
7
|
+
spec.email = ["envek@envek.name"]
|
8
|
+
|
9
|
+
spec.summary = "Extensible metrics for monitoring Ruby on Rails application"
|
10
|
+
spec.description = "Easy collecting your Rails apps metrics"
|
11
|
+
spec.homepage = "https://github.com/evil-metrics/evil-metrics-rails"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "evil-metrics"
|
22
|
+
spec.add_dependency "rails"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "evil/metrics"
|
4
|
+
require "evil/metrics/rails/railtie"
|
5
|
+
|
6
|
+
module Evil
|
7
|
+
module Metrics
|
8
|
+
module Rails
|
9
|
+
LONG_RUNNING_REQUEST_BUCKETS = [
|
10
|
+
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard
|
11
|
+
30, 60, 120, 300, 600, # Sometimes requests may be really long-running
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def controller_handlers
|
16
|
+
@controller_handlers ||= []
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_controller_action(&block)
|
20
|
+
controller_handlers << block
|
21
|
+
end
|
22
|
+
|
23
|
+
def install!
|
24
|
+
Evil::Metrics.configure do
|
25
|
+
group :rails
|
26
|
+
|
27
|
+
counter :requests_total, comment: "A counter of the total number of HTTP requests rails processed."
|
28
|
+
histogram :request_duration, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
|
29
|
+
comment: "A histogram of the response latency."
|
30
|
+
histogram :view_runtime, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
|
31
|
+
comment: "A histogram of the view rendering time."
|
32
|
+
histogram :db_runtime, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
|
33
|
+
comment: "A histogram of the activerecord execution time."
|
34
|
+
|
35
|
+
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
|
36
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
37
|
+
labels = {
|
38
|
+
controller: event.payload[:params]["controller"],
|
39
|
+
action: event.payload[:params]["action"],
|
40
|
+
status: event.payload[:status],
|
41
|
+
format: event.payload[:format],
|
42
|
+
method: event.payload[:method].downcase,
|
43
|
+
}
|
44
|
+
|
45
|
+
rails_requests_total.increment(labels)
|
46
|
+
rails_request_duration.measure(labels, Evil::Metrics::Rails.ms2s(event.duration))
|
47
|
+
rails_view_runtime.measure(labels, Evil::Metrics::Rails.ms2s(event.payload[:view_runtime]))
|
48
|
+
rails_db_runtime.measure(labels, Evil::Metrics::Rails.ms2s(event.payload[:db_runtime]))
|
49
|
+
|
50
|
+
Evil::Metrics::Rails.controller_handlers.each do |handler|
|
51
|
+
handler.call(event, labels)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def ms2s(ms)
|
58
|
+
(ms.to_f / 1000).round(3)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Evil
|
4
|
+
module Metrics
|
5
|
+
module Rails
|
6
|
+
class Railtie < ::Rails::Railtie # :nodoc:
|
7
|
+
config.after_initialize do
|
8
|
+
next unless ::Rails.const_defined?(:Server)
|
9
|
+
|
10
|
+
::Evil::Metrics::Rails.install!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evil-metrics-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Novikov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: evil-metrics
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Easy collecting your Rails apps metrics
|
84
|
+
email:
|
85
|
+
- envek@envek.name
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- evil-metrics-rails.gemspec
|
101
|
+
- lib/evil/metrics/rails.rb
|
102
|
+
- lib/evil/metrics/rails/railtie.rb
|
103
|
+
homepage: https://github.com/evil-metrics/evil-metrics-rails
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Extensible metrics for monitoring Ruby on Rails application
|
127
|
+
test_files: []
|