Sha256: 04059f116476700b5be99aacf7c80c9f339aa24057f42a3dc292272d584351bd
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require "rubygems" require "thread" require "librato/metrics" module Recognizer class Librato def initialize(thread_queue, options) unless thread_queue && options.is_a?(Hash) raise "You must provide a thread queue and options" end unless options[:librato][:email] && options[:librato][:api_key] raise "You must provide a Librato Metrics account email and API key" end ::Librato::Metrics.authenticate(options[:librato][:email], options[:librato][:api_key]) librato = ::Librato::Metrics::Queue.new mutex = Mutex.new Thread.abort_on_exception = true Thread.new do loop do sleep(options[:librato][:flush_interval] || 10) unless librato.queued.empty? puts "Attempting to flush metrics to Librato" mutex.synchronize do librato.submit end puts "Successfully flushed metrics to Librato" end end end Thread.new do loop do graphite_formated = thread_queue.pop puts "Adding metric to queue: #{graphite_formated}" metric = graphite_formated.split(" ") mutex.synchronize do librato.add metric[0].to_sym => {:value => metric[1].to_f, :measure_time => metric[2].to_i} end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
recognizer-0.0.1 | lib/recognizer/librato.rb |