mirror of https://github.com/mastodon/mastodon
Improve StatsD instrumentation
parent
7329fbd8a4
commit
d567f21d4f
@ -0,0 +1,18 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
instrumentation_hostname = ENV.fetch('INSTRUMENTATION_HOSTNAME') { 'localhost' }
|
||||||
|
|
||||||
|
ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
|
||||||
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
|
controller = event.payload[:controller]
|
||||||
|
action = event.payload[:action]
|
||||||
|
format = event.payload[:format] || 'all'
|
||||||
|
format = 'all' if format == '*/*'
|
||||||
|
status = event.payload[:status]
|
||||||
|
key = "#{controller}.#{action}.#{format}.#{instrumentation_hostname}"
|
||||||
|
|
||||||
|
ActiveSupport::Notifications.instrument :performance, action: :measure, measurement: "#{key}.total_duration", value: event.duration
|
||||||
|
ActiveSupport::Notifications.instrument :performance, action: :measure, measurement: "#{key}.db_time", value: event.payload[:db_runtime]
|
||||||
|
ActiveSupport::Notifications.instrument :performance, action: :measure, measurement: "#{key}.view_time", value: event.payload[:view_runtime]
|
||||||
|
ActiveSupport::Notifications.instrument :performance, measurement: "#{key}.status.#{status}"
|
||||||
|
end
|
@ -1,11 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class StatsDMonitor
|
|
||||||
def initialize(app)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue