Module: Yabeda::Rails
- Defined in:
- lib/yabeda/rails.rb,
lib/yabeda/rails/event.rb,
lib/yabeda/rails/config.rb,
lib/yabeda/rails/railtie.rb,
lib/yabeda/rails/version.rb
Overview
Minimal set of Rails-specific metrics for using with Yabeda
Defined Under Namespace
Classes: Config, Event, Railtie
Constant Summary collapse
- 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
- VERSION =
"0.9.0"
Class Method Summary collapse
-
.config ⇒ Object
rubocop: enable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize.
- .controller_handlers ⇒ Object
-
.install! ⇒ Object
Declare metrics and install event handlers for collecting themya rubocop: disable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize.
- .on_controller_action(&block) ⇒ Object
Class Method Details
.config ⇒ Object
rubocop: enable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
73 74 75 |
# File 'lib/yabeda/rails.rb', line 73 def config @config ||= Config.new end |
.controller_handlers ⇒ Object
19 20 21 |
# File 'lib/yabeda/rails.rb', line 19 def controller_handlers @controller_handlers ||= [] end |
.install! ⇒ Object
Declare metrics and install event handlers for collecting themya rubocop: disable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/yabeda/rails.rb', line 29 def install! Yabeda.configure do config = ::Yabeda::Rails.config group :rails counter :requests_total, comment: "A counter of the total number of HTTP requests rails processed.", tags: %i[controller action status format method] histogram :request_duration, tags: %i[controller action status format method], 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.", tags: %i[controller action status format method] histogram :db_runtime, unit: :seconds, buckets: LONG_RUNNING_REQUEST_BUCKETS, comment: "A histogram of the activerecord execution time.", tags: %i[controller action status format method] if config.apdex_target gauge :apdex_target, unit: :seconds, comment: "Tolerable time for Apdex (T value: maximum duration of satisfactory request)" collect { rails_apdex_target.set({}, config.apdex_target) } end ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args| event = Yabeda::Rails::Event.new(*args) rails_requests_total.increment(event.labels) rails_request_duration.measure(event.labels, event.duration) rails_view_runtime.measure(event.labels, event.view_runtime) rails_db_runtime.measure(event.labels, event.db_runtime) Yabeda::Rails.controller_handlers.each do |handler| handler.call(event, event.labels) end end end end |
.on_controller_action(&block) ⇒ Object
23 24 25 |
# File 'lib/yabeda/rails.rb', line 23 def on_controller_action(&block) controller_handlers << block end |