Module: TingYun::Instrumentation::Moped
- Defined in:
- lib/ting_yun/instrumentation/moped.rb
Constant Summary collapse
- MONGODB =
'MongoDB'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #determine_operation_and_collection(operation) ⇒ Object
- #log_with_tingyun_instrumentation(operations, &blk) ⇒ Object
- #record_mongo_duration(duration) ⇒ Object
Class Method Details
.included(instrumented_class) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/ting_yun/instrumentation/moped.rb', line 14 def self.included(instrumented_class) instrumented_class.class_eval do unless instrumented_class.method_defined?(:log_without_tingyun_instrumentation) alias_method :log_without_tingyun_instrumentation, :logging alias_method :logging, :log_with_tingyun_instrumentation end end end |
.instrument ⇒ Object
23 24 25 26 27 |
# File 'lib/ting_yun/instrumentation/moped.rb', line 23 def self.instrument ::Moped::Node.class_eval do include ::TingYun::Instrumentation::Moped end end |
Instance Method Details
#determine_operation_and_collection(operation) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ting_yun/instrumentation/moped.rb', line 43 def determine_operation_and_collection(operation) log_statement = operation.log_inspect.encode("UTF-8") collection = operation.collection if operation.respond_to?(:collection) operation_name = log_statement.split[0] if operation_name == 'COMMAND' && log_statement.include?(":mapreduce") operation_name = 'MAPREDUCE' collection = log_statement[/:mapreduce=>"([^"]+)/,1] elsif operation_name == 'COMMAND' && log_statement.include?(":count") operation_name = 'COUNT' collection = log_statement[/:count=>"([^"]+)/,1] elsif operation_name == 'COMMAND' && log_statement.include?(":aggregate") operation_name = 'AGGREGATE' collection = log_statement[/:aggregate=>"([^"]+)/,1] elsif operation_name == 'COMMAND' && log_statement.include?(":findAndModify") operation_name = 'FIND_AND_MODIFY' collection = log_statement[/:findAndModify=>"([^"]+)/,1] end return operation_name, collection end |
#log_with_tingyun_instrumentation(operations, &blk) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ting_yun/instrumentation/moped.rb', line 30 def log_with_tingyun_instrumentation(operations, &blk) operation_name, collection = determine_operation_and_collection(operations.first) operation = TingYun::Agent::Datastore::Mongo.transform_operation(operation_name) res = nil database = ["database"] || [:database] TingYun::Agent::Datastore.wrap(MONGODB, operation, collection, ip_address, port, database, method(:record_mongo_duration)) do res = log_without_tingyun_instrumentation(operations, &blk) end res end |
#record_mongo_duration(duration) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/ting_yun/instrumentation/moped.rb', line 65 def record_mongo_duration(duration) state = TingYun::Agent::TransactionState.tl_get if state state.timings.mon_duration = state.timings.mon_duration + duration * 1000 end end |