about summary refs log tree commit diff
path: root/config
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-09-29 03:16:44 +0200
committerGitHub <noreply@github.com>2017-09-29 03:16:44 +0200
commit35a8cafa35c12d33f9f761bacab189397b34045f (patch)
tree2ab7c244c04ad8a7be71b284e89e6200e923e90c /config
parentf4ca116ea8f86057e91c99a1cd8e64e116c86746 (diff)
Replace self-rolled statsd instrumention with localshred/nsa (#5118)
Diffstat (limited to 'config')
-rw-r--r--config/environments/production.rb5
-rw-r--r--config/initializers/statsd.rb23
2 files changed, 10 insertions, 18 deletions
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 397ea48da..5705ffcfe 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -90,11 +90,6 @@ Rails.application.configure do
 
   config.action_mailer.delivery_method = ENV.fetch('SMTP_DELIVERY_METHOD', 'smtp').to_sym
 
-  config.to_prepare do
-    StatsD.backend = StatsD::Instrument::Backends::NullBackend.new if ENV['STATSD_ADDR'].blank?
-    Sidekiq::Logging.logger.level = Logger::WARN
-  end
-
   config.action_dispatch.default_headers = {
     'Server'                 => 'Mastodon',
     'X-Frame-Options'        => 'DENY',
diff --git a/config/initializers/statsd.rb b/config/initializers/statsd.rb
index f00b1d401..17a176174 100644
--- a/config/initializers/statsd.rb
+++ b/config/initializers/statsd.rb
@@ -1,18 +1,15 @@
 # frozen_string_literal: true
-RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
 
-StatsD.prefix              = 'mastodon'
-StatsD.default_sample_rate = 1
+if ENV['STATSD_ADDR'].present?
+  host, port = ENV['STATSD_ADDR'].split(':')
 
-def clean_name(str)
-  str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_')
-end
-
-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 = ::Statsd.new(host, port)
+  statsd.namespace = ['Mastodon', Rails.env].join('.')
 
-  StatsD.send(action.to_s, key_name, (value || 1))
+  ::NSA.inform_statsd(statsd) do |informant|
+    informant.collect(:action_controller, :web)
+    informant.collect(:active_record, :db)
+    informant.collect(:cache, :cache)
+    informant.collect(:sidekiq, :sidekiq)
+  end
 end