2017-01-19 00:44:29 +02:00
|
|
|
# frozen_string_literal: true
|
2017-01-26 20:46:52 +02:00
|
|
|
RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
|
2017-01-19 00:44:29 +02:00
|
|
|
|
|
|
|
StatsD.prefix = 'mastodon'
|
|
|
|
StatsD.default_sample_rate = 1
|
|
|
|
|
2017-01-26 20:46:52 +02:00
|
|
|
def clean_name(str)
|
|
|
|
str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_')
|
|
|
|
end
|
|
|
|
|
2017-01-26 20:08:05 +02:00
|
|
|
ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload|
|
|
|
|
action = payload[:action] || :increment
|
|
|
|
measurement = payload[:measurement]
|
|
|
|
value = payload[:value]
|
2017-01-26 20:46:52 +02:00
|
|
|
key_name = clean_name("#{name}.#{measurement}")
|
2017-01-19 00:44:29 +02:00
|
|
|
|
2017-01-26 20:08:05 +02:00
|
|
|
StatsD.send(action.to_s, key_name, (value || 1))
|
2017-01-19 00:44:29 +02:00
|
|
|
end
|