yabeda-rails 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aa7de0e49e6d7ec219880b9cac720b691118fe263ad5cdac3400627f82e35409
4
+ data.tar.gz: 0b220d9d05316e537622d9eba39f26fb1570e7b5979817b8dce05f172c3b5039
5
+ SHA512:
6
+ metadata.gz: bdce37215d1e3f562018d011fa446492587bbc4cabb694db9d73d7d7056c73e4b4e64aff3bd11dfdcec0dbe2024da8f587ab5f7cde988de721aab0b834b95cd3
7
+ data.tar.gz: 13bbdce6455f6b5af379034f895809320f585ecb144906837a01e06e23477ff767e26f538249d833201a088a33f42f588248a42dfe39d1e01c74462b3781dfac
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -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
+
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
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 yabeda-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
@@ -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.
@@ -0,0 +1,55 @@
1
+ # Yabeda::[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 'yabeda-rails'
13
+ # Then add monitoring system adapter, e.g.:
14
+ # gem 'yabeda-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
+ Yabeda::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/yabeda-rb/yabeda-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"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "yabeda/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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yabeda"
4
+ require "yabeda/rails/railtie"
5
+
6
+ module Yabeda
7
+ module Rails
8
+ LONG_RUNNING_REQUEST_BUCKETS = [
9
+ 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard
10
+ 30, 60, 120, 300, 600, # Sometimes requests may be really long-running
11
+ ].freeze
12
+
13
+ class << self
14
+ def controller_handlers
15
+ @controller_handlers ||= []
16
+ end
17
+
18
+ def on_controller_action(&block)
19
+ controller_handlers << block
20
+ end
21
+
22
+ def install!
23
+ Yabeda.configure do
24
+ group :rails
25
+
26
+ counter :requests_total, comment: "A counter of the total number of HTTP requests rails processed."
27
+ histogram :request_duration, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
28
+ comment: "A histogram of the response latency."
29
+ histogram :view_runtime, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
30
+ comment: "A histogram of the view rendering time."
31
+ histogram :db_runtime, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
32
+ comment: "A histogram of the activerecord execution time."
33
+
34
+ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
35
+ event = ActiveSupport::Notifications::Event.new(*args)
36
+ labels = {
37
+ controller: event.payload[:params]["controller"],
38
+ action: event.payload[:params]["action"],
39
+ status: event.payload[:status],
40
+ format: event.payload[:format],
41
+ method: event.payload[:method].downcase,
42
+ }
43
+
44
+ rails_requests_total.increment(labels)
45
+ rails_request_duration.measure(labels, Yabeda::Rails.ms2s(event.duration))
46
+ rails_view_runtime.measure(labels, Yabeda::Rails.ms2s(event.payload[:view_runtime]))
47
+ rails_db_runtime.measure(labels, Yabeda::Rails.ms2s(event.payload[:db_runtime]))
48
+
49
+ Yabeda::Rails.controller_handlers.each do |handler|
50
+ handler.call(event, labels)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def ms2s(ms)
57
+ (ms.to_f / 1000).round(3)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie # :nodoc:
6
+ config.after_initialize do
7
+ next unless ::Rails.const_defined?(:Server)
8
+
9
+ ::Yabeda::Rails.install!
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Rails
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "yabeda/rails/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "yabeda-rails"
9
+ spec.version = Yabeda::Rails::VERSION
10
+ spec.authors = ["Andrey Novikov"]
11
+ spec.email = ["envek@envek.name"]
12
+
13
+ spec.summary = "Extensible metrics for monitoring Ruby on Rails application"
14
+ spec.description = "Easy collecting your Rails apps metrics"
15
+ spec.homepage = "https://github.com/yabeda-rb/yabeda-rails"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "yabeda"
26
+ spec.add_dependency "rails"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yabeda-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Novikov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yabeda
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
+ - lib/yabeda/rails.rb
101
+ - lib/yabeda/rails/railtie.rb
102
+ - lib/yabeda/rails/version.rb
103
+ - yabeda-rails.gemspec
104
+ homepage: https://github.com/yabeda-rb/yabeda-rails
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.7.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Extensible metrics for monitoring Ruby on Rails application
128
+ test_files: []