Skip to content

Instantly share code, notes, and snippets.

@tompesman
Created September 15, 2017 13:40
Show Gist options
  • Save tompesman/c83c04b7f1039e6a042f21ee7af24560 to your computer and use it in GitHub Desktop.
Save tompesman/c83c04b7f1039e6a042f21ee7af24560 to your computer and use it in GitHub Desktop.
Stats processor file for Pushr
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