Class: TingYun::Agent::Collector::SqlTrace
- Inherits:
-
Metrics::Stats
- Object
- Metrics::Stats
- TingYun::Agent::Collector::SqlTrace
- Includes:
- Support::Coerce
- Defined in:
- lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb
Instance Attribute Summary collapse
-
#action_metric_name ⇒ Object
readonly
Returns the value of attribute action_metric_name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#slow_sql ⇒ Object
readonly
Returns the value of attribute slow_sql.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes inherited from Metrics::Stats
#call_count, #max_call_time, #min_call_time, #sum_of_squares, #total_call_time, #total_exclusive_time
Instance Method Summary collapse
- #aggregate(slow_sql, action_name, uri) ⇒ Object
-
#initialize(normalized_query, slow_sql, action_name, uri) ⇒ SqlTrace
constructor
A new instance of SqlTrace.
- #need_to_explain? ⇒ Boolean
- #prepare_to_send ⇒ Object
- #to_collector_array(encoder) ⇒ Object
Methods included from Support::Coerce
event_params, float, int, int_or_nil, log_failure, string, url_encode
Methods inherited from Metrics::Stats
#==, create_from_hash, #increment_count, #is_reset?, #merge, #merge!, #metrics, #record, #record_apdex, #record_data_point, #reset, #to_json, #to_s
Constructor Details
#initialize(normalized_query, slow_sql, action_name, uri) ⇒ SqlTrace
Returns a new instance of SqlTrace.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 19 def initialize(normalized_query, slow_sql, action_name, uri) super() @params = {} @action_metric_name = action_name @slow_sql = slow_sql @sql = normalized_query @uri = uri @params[:stacktrace] = slow_sql.backtrace record_data_point(float(slow_sql.duration)) end |
Instance Attribute Details
#action_metric_name ⇒ Object (readonly)
Returns the value of attribute action_metric_name.
13 14 15 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 13 def action_metric_name @action_metric_name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
17 18 19 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 17 def params @params end |
#slow_sql ⇒ Object (readonly)
Returns the value of attribute slow_sql.
16 17 18 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 16 def slow_sql @slow_sql end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
15 16 17 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 15 def sql @sql end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
14 15 16 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 14 def uri @uri end |
Instance Method Details
#aggregate(slow_sql, action_name, uri) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 31 def aggregate(slow_sql, action_name, uri) duration = slow_sql.duration if duration > max_call_time @action_metric_name = action_name @slow_sql = slow_sql @uri = uri @params[:stacktrace] = slow_sql.backtrace end record_data_point(float(duration)) end |
#need_to_explain? ⇒ Boolean
49 50 51 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 49 def need_to_explain? Agent.config[:'nbs.action_tracer.explain_enabled'] && @slow_sql.duration * 1000 > TingYun::Agent.config[:'nbs.action_tracer.explain_threshold'] end |
#prepare_to_send ⇒ Object
43 44 45 46 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 43 def prepare_to_send @sql = @slow_sql.sql unless Agent.config[:'nbs.action_tracer.record_sql'].to_s == 'obfuscated' @params[:explainPlan] = @slow_sql.explain if need_to_explain? end |
#to_collector_array(encoder) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb', line 56 def to_collector_array(encoder) [ @slow_sql.start_time, string(@action_metric_name), string(@slow_sql.metric_name), string(@uri||@action_metric_name), string(@sql), int(@call_count), TingYun::Helper.time_to_millis(@total_call_time), TingYun::Helper.time_to_millis(@max_call_time), TingYun::Helper.time_to_millis(@min_call_time), encoder.encode(@params) ] end |