class EventsEmitter::Graphite
Attributes
base_key[RW]
storage[RW]
timestamp[W]
Public Class Methods
config()
click to toggle source
# File lib/events_emitter/graphite.rb, line 51 def self.config @config ||= { graphite_host: 'graphite123.example.com', graphite_port: 2003, memcached_uri: '127.0.0.1:11211', keys: ["key1"] } end
new(storage = Dalli::Client.new(Graphite.config[:memcached_uri]))
click to toggle source
# File lib/events_emitter/graphite.rb, line 9 def initialize(storage = Dalli::Client.new(Graphite.config[:memcached_uri])) self.storage = storage self.base_key = "ofw.rails.#{hostname}" end
Public Instance Methods
compose_key(key)
click to toggle source
# File lib/events_emitter/graphite.rb, line 35 def compose_key(key) "#{base_key}.#{key}" end
config()
click to toggle source
# File lib/events_emitter/graphite.rb, line 47 def config self.class.config end
filtering_steps()
click to toggle source
# File lib/events_emitter/graphite.rb, line 43 def filtering_steps FILTERING_STEPS end
hostname()
click to toggle source
# File lib/events_emitter/graphite.rb, line 14 def hostname @hostname ||= %x(hostname -s).strip end
record(key, amount)
click to toggle source
# File lib/events_emitter/graphite.rb, line 31 def record(key, amount) storage.incr(compose_key(key), amount, nil, amount) end
send_batch()
click to toggle source
# File lib/events_emitter/graphite.rb, line 18 def send_batch now = timestamp composed_keys = config[:keys].map{ |e| compose_key(e) } values = storage.get_multi(composed_keys) Socket.tcp(config[:graphite_host], config[:graphite_port]) do |socket| values.each do |key, value| socket.puts("#{key} #{value.to_i} #{now}") end end end
timestamp()
click to toggle source
# File lib/events_emitter/graphite.rb, line 39 def timestamp @timestamp || Time.now.utc.to_i end