From 35a8cafa35c12d33f9f761bacab189397b34045f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 29 Sep 2017 03:16:44 +0200 Subject: Replace self-rolled statsd instrumention with localshred/nsa (#5118) --- config/initializers/statsd.rb | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'config/initializers') 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 -- cgit