Module: TingYun::Agent::Datastore

Defined in:
lib/ting_yun/agent/datastore.rb,
lib/ting_yun/agent/datastore/mongo.rb,
lib/ting_yun/agent/datastore/metric_helper.rb

Defined Under Namespace

Modules: MetricHelper, Mongo

Class Method Summary collapse

Class Method Details

.wrap(product, operation, collection = nil, ip_address = nil, port = nil, dbname = nil, callback = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ting_yun/agent/datastore.rb', line 10

def self.wrap(product, operation, collection = nil, ip_address = nil, port = nil, dbname=nil,  callback = nil )
  return yield unless operation
  klass_name, *metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for(product, operation, ip_address ,
                                                                             port,
                                                                  dbname,collection )
  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, {}, nil, klass_name) do
    t0 = Time.now
    begin
      yield
    ensure
      elapsed_time = (Time.now - t0).to_f
      if callback
        callback.call(elapsed_time)
      end
      config = {
          :product => product,
          :operation => operation,
          :database => collection,
          :host => ip_address,
          :port => port,
          :type => product,
          :nosql => klass_name
      }
      ::TingYun::Agent::Collector::TransactionSampler.notice_nosql_statement(config,elapsed_time*1000, :nosql)
    end
  end
end