Class: EventsEmitter::Graphite
- Inherits:
-
Object
- Object
- EventsEmitter::Graphite
- Defined in:
- lib/events_emitter/graphite.rb
Instance Attribute Summary collapse
-
#base_key ⇒ Object
Returns the value of attribute base_key.
-
#storage ⇒ Object
Returns the value of attribute storage.
- #timestamp ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #compose_key(key) ⇒ Object
- #config ⇒ Object
- #filtering_steps ⇒ Object
- #hostname ⇒ Object
-
#initialize(storage = Dalli::Client.new(Graphite.config[:memcached_uri])) ⇒ Graphite
constructor
A new instance of Graphite.
- #record(key, amount) ⇒ Object
- #send_batch ⇒ Object
Constructor Details
#initialize(storage = Dalli::Client.new(Graphite.config[:memcached_uri])) ⇒ Graphite
Returns a new instance of Graphite.
9 10 11 12 |
# 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 |
Instance Attribute Details
#base_key ⇒ Object
Returns the value of attribute base_key.
6 7 8 |
# File 'lib/events_emitter/graphite.rb', line 6 def base_key @base_key end |
#storage ⇒ Object
Returns the value of attribute storage.
6 7 8 |
# File 'lib/events_emitter/graphite.rb', line 6 def storage @storage end |
#timestamp ⇒ Object
39 40 41 |
# File 'lib/events_emitter/graphite.rb', line 39 def @timestamp || Time.now.utc.to_i end |
Class Method Details
.config ⇒ Object
51 52 53 54 55 56 57 |
# 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 |
Instance Method Details
#compose_key(key) ⇒ Object
35 36 37 |
# File 'lib/events_emitter/graphite.rb', line 35 def compose_key(key) "#{base_key}.#{key}" end |
#config ⇒ Object
47 48 49 |
# File 'lib/events_emitter/graphite.rb', line 47 def config self.class.config end |
#filtering_steps ⇒ Object
43 44 45 |
# File 'lib/events_emitter/graphite.rb', line 43 def filtering_steps FILTERING_STEPS end |
#hostname ⇒ Object
14 15 16 |
# File 'lib/events_emitter/graphite.rb', line 14 def hostname @hostname ||= %x(hostname -s).strip end |
#record(key, amount) ⇒ Object
31 32 33 |
# File 'lib/events_emitter/graphite.rb', line 31 def record(key, amount) storage.incr(compose_key(key), amount, nil, amount) end |
#send_batch ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/events_emitter/graphite.rb', line 18 def send_batch now = 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 |