mirror of https://github.com/mastodon/mastodon
Replace self-rolled statsd instrumention with localshred/nsa (#5118)
parent
f4ca116ea8
commit
35a8cafa35
@ -1,18 +1,15 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
|
|
||||||
|
|
||||||
StatsD.prefix = 'mastodon'
|
if ENV['STATSD_ADDR'].present?
|
||||||
StatsD.default_sample_rate = 1
|
host, port = ENV['STATSD_ADDR'].split(':')
|
||||||
|
|
||||||
def clean_name(str)
|
statsd = ::Statsd.new(host, port)
|
||||||
str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_')
|
statsd.namespace = ['Mastodon', Rails.env].join('.')
|
||||||
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))
|
::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
|
end
|
||||||
|
Loading…
Reference in New Issue