From f6a5977f0b2986b15ca8254123053e1a59647cd1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 26 Jan 2017 19:46:52 +0100 Subject: Fix key names in statsd --- config/initializers/statsd.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config/initializers/statsd.rb b/config/initializers/statsd.rb index 4e772a5ed..f00b1d401 100644 --- a/config/initializers/statsd.rb +++ b/config/initializers/statsd.rb @@ -1,13 +1,18 @@ # frozen_string_literal: true +RESERVED_CHARACTERS_REGEX = /[\:\|\@]/ StatsD.prefix = 'mastodon' 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| action = payload[:action] || :increment measurement = payload[:measurement] value = payload[:value] - key_name = "#{name}.#{measurement}" + key_name = clean_name("#{name}.#{measurement}") StatsD.send(action.to_s, key_name, (value || 1)) end -- cgit