class Mmtrix::Agent::SqlTrace
Attributes
database_metric_name[R]
params[R]
path[R]
slow_sql[R]
sql[R]
sql_id[R]
url[R]
Public Class Methods
new(normalized_query, slow_sql, path, uri)
click to toggle source
Calls superclass method
# File lib/mmtrix/agent/sql_sampler.rb, line 255 def initialize(normalized_query, slow_sql, path, uri) super() @params = {} @sql_id = consistent_hash(normalized_query) set_primary slow_sql, path, uri record_data_point(float(slow_sql.duration)) end
Public Instance Methods
aggregate(slow_sql, path, uri)
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 272 def aggregate(slow_sql, path, uri) if slow_sql.duration > max_call_time set_primary slow_sql, path, uri end record_data_point(float(slow_sql.duration)) end
aggregate_trace(trace)
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 280 def aggregate_trace(trace) aggregate(trace.slow_sql, trace.path, trace.url) end
need_to_explain?()
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 294 def need_to_explain? Agent.config[:'slow_sql.explain_enabled'] end
need_to_obfuscate?()
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 290 def need_to_obfuscate? Agent.config[:'slow_sql.record_sql'].to_s == 'obfuscated' end
prepare_to_send()
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 284 def prepare_to_send params[:explain_plan] = @slow_sql.explain if need_to_explain? @sql = @slow_sql.obfuscate if need_to_obfuscate? @slow_sql.prepare_to_send end
set_primary(slow_sql, path, uri)
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 263 def set_primary(slow_sql, path, uri) @slow_sql = slow_sql @sql = slow_sql.sql @database_metric_name = slow_sql.metric_name @path = path @url = uri @params[:backtrace] = slow_sql.backtrace if slow_sql.backtrace end
to_collector_array(encoder)
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 300 def to_collector_array(encoder) [ string(@path), string(@url), int(@sql_id), string(@sql), string(@database_metric_name), int(@call_count), Helper.time_to_millis(@total_call_time), Helper.time_to_millis(@min_call_time), Helper.time_to_millis(@max_call_time), encoder.encode(@params) ] end
Private Instance Methods
consistent_hash(string)
click to toggle source
# File lib/mmtrix/agent/sql_sampler.rb, line 315 def consistent_hash(string) # need to hash the same way in every process Digest::MD5.hexdigest(string).hex \ .modulo(2**31-1) # ensure sql_id fits in an INT(11) end