You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
547 B

  1. # frozen_string_literal: true
  2. RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
  3. StatsD.prefix = 'mastodon'
  4. StatsD.default_sample_rate = 1
  5. def clean_name(str)
  6. str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_')
  7. end
  8. ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload|
  9. action = payload[:action] || :increment
  10. measurement = payload[:measurement]
  11. value = payload[:value]
  12. key_name = clean_name("#{name}.#{measurement}")
  13. StatsD.send(action.to_s, key_name, (value || 1))
  14. end