forked from treehouse/mastodon
Replace self-rolled statsd instrumention with localshred/nsa (#5118)
parent
f4ca116ea8
commit
35a8cafa35
2
Gemfile
2
Gemfile
|
@ -42,6 +42,7 @@ gem 'kaminari', '~> 1.0'
|
|||
gem 'link_header', '~> 0.0'
|
||||
gem 'mime-types', '~> 3.1'
|
||||
gem 'nokogiri', '~> 1.7'
|
||||
gem 'nsa', '~> 0.2'
|
||||
gem 'oj', '~> 3.0'
|
||||
gem 'ostatus2', '~> 2.0'
|
||||
gem 'ox', '~> 2.5'
|
||||
|
@ -64,7 +65,6 @@ gem 'sidekiq-bulk', '~>0.1.1'
|
|||
gem 'simple-navigation', '~> 4.0'
|
||||
gem 'simple_form', '~> 3.4'
|
||||
gem 'sprockets-rails', '~> 3.2', require: 'sprockets/railtie'
|
||||
gem 'statsd-instrument', '~> 2.1'
|
||||
gem 'twitter-text', '~> 1.14'
|
||||
gem 'tzinfo-data', '~> 1.2017'
|
||||
gem 'webpacker', '~> 3.0'
|
||||
|
|
|
@ -289,6 +289,11 @@ GEM
|
|||
mini_portile2 (~> 2.2.0)
|
||||
nokogumbo (1.4.13)
|
||||
nokogiri
|
||||
nsa (0.2.4)
|
||||
activesupport (>= 4.2, < 6)
|
||||
concurrent-ruby (~> 1.0.0)
|
||||
sidekiq (>= 3.5.0)
|
||||
statsd-ruby (~> 1.2.0)
|
||||
oj (3.3.5)
|
||||
openssl (2.0.5)
|
||||
orm_adapter (0.5.0)
|
||||
|
@ -483,7 +488,7 @@ GEM
|
|||
sshkit (1.14.0)
|
||||
net-scp (>= 1.1.2)
|
||||
net-ssh (>= 2.8.0)
|
||||
statsd-instrument (2.1.4)
|
||||
statsd-ruby (1.2.1)
|
||||
strong_migrations (0.1.9)
|
||||
activerecord (>= 3.2.0)
|
||||
temple (0.8.0)
|
||||
|
@ -578,6 +583,7 @@ DEPENDENCIES
|
|||
microformats (~> 4.0)
|
||||
mime-types (~> 3.1)
|
||||
nokogiri (~> 1.7)
|
||||
nsa (~> 0.2)
|
||||
oj (~> 3.0)
|
||||
ostatus2 (~> 2.0)
|
||||
ox (~> 2.5)
|
||||
|
@ -617,7 +623,6 @@ DEPENDENCIES
|
|||
simple_form (~> 3.4)
|
||||
simplecov (~> 0.14)
|
||||
sprockets-rails (~> 3.2)
|
||||
statsd-instrument (~> 2.1)
|
||||
strong_migrations
|
||||
twitter-text (~> 1.14)
|
||||
tzinfo-data (~> 1.2017)
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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.send(action.to_s, key_name, (value || 1))
|
||||
statsd = ::Statsd.new(host, port)
|
||||
statsd.namespace = ['Mastodon', Rails.env].join('.')
|
||||
|
||||
::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
|
||||
|
|
Loading…
Reference in New Issue