forked from treehouse/mastodon
Fix key names in statsd
parent
d567f21d4f
commit
f6a5977f0b
|
@ -1,13 +1,18 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
|
||||||
|
|
||||||
StatsD.prefix = 'mastodon'
|
StatsD.prefix = 'mastodon'
|
||||||
StatsD.default_sample_rate = 1
|
StatsD.default_sample_rate = 1
|
||||||
|
|
||||||
|
def clean_name(str)
|
||||||
|
str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_')
|
||||||
|
end
|
||||||
|
|
||||||
ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload|
|
ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload|
|
||||||
action = payload[:action] || :increment
|
action = payload[:action] || :increment
|
||||||
measurement = payload[:measurement]
|
measurement = payload[:measurement]
|
||||||
value = payload[:value]
|
value = payload[:value]
|
||||||
key_name = "#{name}.#{measurement}"
|
key_name = clean_name("#{name}.#{measurement}")
|
||||||
|
|
||||||
StatsD.send(action.to_s, key_name, (value || 1))
|
StatsD.send(action.to_s, key_name, (value || 1))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue