Created
September 15, 2017 13:40
-
-
Save tompesman/c83c04b7f1039e6a042f21ee7af24560 to your computer and use it in GitHub Desktop.
Stats processor file for Pushr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'librato/metrics' | |
require_relative 'metrics' | |
module Pushr | |
class StatsProcessor | |
# name, start, finish, id, payload | |
def call(_, start, finish, _, payload) | |
messagetype = payload[:type]['Pushr::Message'.size, payload[:type].size].downcase | |
hsh = { measure_time: Time.now, value: ((finish - start) * 1000) } | |
Pushr::Metrics.queue.add "#{payload[:app]}:message:#{messagetype}:time" => hsh | |
end | |
end | |
end | |
Librato::Metrics.authenticate ENV['LIBRATO_EMAIL'], ENV['LIBRATO_KEY'] | |
Pushr::Metrics.queue_constructor = Librato::Metrics::Queue.method(:new) | |
Pushr::Metrics.logger = ::Pushr::Daemon.logger | |
Pushr::Metrics.exception_handler = ::Airbrake.method(:notify) if defined?(::Airbrake) | |
ActiveSupport::Notifications.subscribe('message', Pushr::StatsProcessor.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment