Class: Sq::Dbsync::Loggers::Graphite
- Defined in:
- lib/sq/dbsync/loggers.rb
Overview
Logs metric run time to graphite.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Graphite
constructor
A new instance of Graphite.
- #measure(label, &block) ⇒ Object
- #record_metric(timestamp, name, value) ⇒ Object
Methods inherited from Abstract
Constructor Details
#initialize(opts) ⇒ Graphite
Returns a new instance of Graphite.
92 93 94 |
# File 'lib/sq/dbsync/loggers.rb', line 92 def initialize(opts) @opts = opts end |
Instance Method Details
#measure(label, &block) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/sq/dbsync/loggers.rb', line 96 def measure(label, &block) start_time = Time.now.utc block.call ensure end_time = Time.now.utc record_metric(end_time.to_i, label, end_time - start_time) end |
#record_metric(timestamp, name, value) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/sq/dbsync/loggers.rb', line 104 def record_metric(, name, value) msg = "#{@opts.fetch(:prefix, 'dbsync')}.#{name} #{value} #{}\n" s = TCPSocket.new(@opts[:host], @opts.fetch(:port, 2003)) s.send msg, 0 s.close end |