diff options
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/instrumentation.rb | 18 | ||||
-rw-r--r-- | config/initializers/statsd.rb | 22 | ||||
-rw-r--r-- | config/initializers/timeout.rb | 5 |
3 files changed, 32 insertions, 13 deletions
diff --git a/config/initializers/instrumentation.rb b/config/initializers/instrumentation.rb new file mode 100644 index 000000000..8483f2be2 --- /dev/null +++ b/config/initializers/instrumentation.rb @@ -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 diff --git a/config/initializers/statsd.rb b/config/initializers/statsd.rb index c9c754e7f..f00b1d401 100644 --- a/config/initializers/statsd.rb +++ b/config/initializers/statsd.rb @@ -1,20 +1,18 @@ # frozen_string_literal: true +RESERVED_CHARACTERS_REGEX = /[\:\|\@]/ StatsD.prefix = 'mastodon' StatsD.default_sample_rate = 1 -StatsDMonitor.extend(StatsD::Instrument) -StatsDMonitor.statsd_measure(:call, 'request.duration') +def clean_name(str) + str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_') +end -STATSD_REQUEST_METRICS = { - 'request.status.success' => 200, - 'request.status.not_found' => 404, - 'request.status.too_many_requests' => 429, - 'request.status.internal_server_error' => 500, -}.freeze +ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload| + action = payload[:action] || :increment + measurement = payload[:measurement] + value = payload[:value] + key_name = clean_name("#{name}.#{measurement}") -STATSD_REQUEST_METRICS.each do |name, code| - StatsDMonitor.statsd_count_if(:call, name) do |status, _env, _body| - status.to_i == code - end + StatsD.send(action.to_s, key_name, (value || 1)) end diff --git a/config/initializers/timeout.rb b/config/initializers/timeout.rb index 1e6315b2b..643780884 100644 --- a/config/initializers/timeout.rb +++ b/config/initializers/timeout.rb @@ -1 +1,4 @@ -Rack::Timeout.timeout = 30 if Rails.env.production? +if Rails.env.production? + Rack::Timeout.service_timeout = 15 + Rack::Timeout::Logger.disable +end |