Skip to content

Commit

Permalink
Rename Evil Metrics to Yabeda
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Oct 17, 2018
1 parent 25c2ab4 commit 2f01582
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in evil-metrics-rails.gemspec
# Specify your gem's dependencies in yabeda-rails.gemspec
gemspec

group :development, :test do
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Evil::Metrics::[Rails]
# Yabeda::[Rails]

Built-in metrics for out-of-the box [Rails] applications monitoring

Expand All @@ -9,9 +9,9 @@ if your monitoring system already collects Rails metrics (e.g. NewRelic) then yo
Add this line to your application's Gemfile:

```ruby
gem 'evil-metrics-rails'
gem 'yabeda-rails'
# Then add monitoring system adapter, e.g.:
# gem 'evil-metrics-prometheus'
# gem 'yabeda-prometheus'
```

And then execute:
Expand All @@ -31,7 +31,7 @@ And then execute:
- `on_controller_action`: Allows to collect

```ruby
Evil::Metrics::Rails.on_controller_action do |event, labels|
Yabeda::Rails.on_controller_action do |event, labels|
next unless event.payload[:ext_service_runtime]
time_in_seconds = event.payload[:ext_service_runtime] / 1000.0
rails_ext_service_runtime.measure(labels, time_in_seconds)
Expand All @@ -46,7 +46,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/evil-metrics/evil-metrics-rails.
Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-rails.

## License

Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "evil/metrics/rails"
require "yabeda/rails"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
63 changes: 0 additions & 63 deletions lib/evil/metrics/rails.rb

This file was deleted.

15 changes: 0 additions & 15 deletions lib/evil/metrics/rails/railtie.rb

This file was deleted.

61 changes: 61 additions & 0 deletions lib/yabeda/rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require "yabeda"
require "yabeda/rails/railtie"

module Yabeda
module Rails
LONG_RUNNING_REQUEST_BUCKETS = [
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard
30, 60, 120, 300, 600, # Sometimes requests may be really long-running
].freeze

class << self
def controller_handlers
@controller_handlers ||= []
end

def on_controller_action(&block)
controller_handlers << block
end

def install!
Yabeda.configure do
group :rails

counter :requests_total, comment: "A counter of the total number of HTTP requests rails processed."
histogram :request_duration, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
comment: "A histogram of the response latency."
histogram :view_runtime, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
comment: "A histogram of the view rendering time."
histogram :db_runtime, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS,
comment: "A histogram of the activerecord execution time."

ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
labels = {
controller: event.payload[:params]["controller"],
action: event.payload[:params]["action"],
status: event.payload[:status],
format: event.payload[:format],
method: event.payload[:method].downcase,
}

rails_requests_total.increment(labels)
rails_request_duration.measure(labels, Yabeda::Rails.ms2s(event.duration))
rails_view_runtime.measure(labels, Yabeda::Rails.ms2s(event.payload[:view_runtime]))
rails_db_runtime.measure(labels, Yabeda::Rails.ms2s(event.payload[:db_runtime]))

Yabeda::Rails.controller_handlers.each do |handler|
handler.call(event, labels)
end
end
end
end

def ms2s(ms)
(ms.to_f / 1000).round(3)
end
end
end
end
13 changes: 13 additions & 0 deletions lib/yabeda/rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Yabeda
module Rails
class Railtie < ::Rails::Railtie # :nodoc:
config.after_initialize do
next unless ::Rails.const_defined?(:Server)

::Yabeda::Rails.install!
end
end
end
end
7 changes: 7 additions & 0 deletions lib/yabeda/rails/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Yabeda
module Rails
VERSION = "0.1.1"
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "evil/metrics/rails"
require "yabeda/rails"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
4 changes: 2 additions & 2 deletions spec/evil/prome/rails_spec.rb → spec/yabeda/rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

RSpec.describe Evil::Metrics::Rails do
RSpec.describe Yabeda::Rails do
it "has a version number" do
expect(Evil::Metrics::Rails::VERSION).not_to be nil
expect(Yabeda::Rails::VERSION).not_to be nil
end

it "does something useful" do
Expand Down
12 changes: 8 additions & 4 deletions evil-metrics-rails.gemspec → yabeda-rails.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# frozen_string_literal: true

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "yabeda/rails/version"

Gem::Specification.new do |spec|
spec.name = "evil-metrics-rails"
spec.version = "0.1.0"
spec.name = "yabeda-rails"
spec.version = Yabeda::Rails::VERSION
spec.authors = ["Andrey Novikov"]
spec.email = ["[email protected]"]

spec.summary = "Extensible metrics for monitoring Ruby on Rails application"
spec.description = "Easy collecting your Rails apps metrics"
spec.homepage = "https://github.com/evil-metrics/evil-metrics-rails"
spec.homepage = "https://github.com/yabeda-rb/yabeda-rails"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject do |f|
Expand All @@ -18,7 +22,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "evil-metrics"
spec.add_dependency "yabeda"
spec.add_dependency "rails"

spec.add_development_dependency "bundler", "~> 1.16"
Expand Down

0 comments on commit 2f01582

Please sign in to comment.