Module: Yabeda::Rails
- Defined in:
- lib/yabeda/rails.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: 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.7.2"
Class Method Summary collapse
- .controller_handlers ⇒ Object
-
.install! ⇒ Object
Declare metrics and install event handlers for collecting themya rubocop: disable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize.
-
.ms2s(milliseconds) ⇒ Object
rubocop: enable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize.
- .on_controller_action(&block) ⇒ Object
Class Method Details
.controller_handlers ⇒ Object
16 17 18 |
# File 'lib/yabeda/rails.rb', line 16 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
26 27 28 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 |
# File 'lib/yabeda/rails.rb', line 26 def install! Yabeda.configure do 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] 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, } labels.merge!(event.payload.slice(*Yabeda..keys - labels.keys)) 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 |
.ms2s(milliseconds) ⇒ Object
rubocop: enable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
70 71 72 |
# File 'lib/yabeda/rails.rb', line 70 def ms2s(milliseconds) (milliseconds.to_f / 1000).round(3) end |
.on_controller_action(&block) ⇒ Object
20 21 22 |
# File 'lib/yabeda/rails.rb', line 20 def on_controller_action(&block) controller_handlers << block end |