forked from yabeda-rb/yabeda-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
99 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| | ||
|
@@ -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" | ||
|