Class: NewRelic::Agent::SqlTrace
- Inherits:
-
MethodTraceStats
- Object
- StatsBase
- MethodTraceStats
- NewRelic::Agent::SqlTrace
- Defined in:
- lib/new_relic/agent/sql_sampler.rb
Instance Attribute Summary collapse
-
#database_metric_name ⇒ Object
readonly
Returns the value of attribute database_metric_name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
-
#sql_id ⇒ Object
readonly
Returns the value of attribute sql_id.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Attributes inherited from StatsBase
#call_count, #max_call_time, #min_call_time, #sum_of_squares, #total_call_time, #total_exclusive_time
Instance Method Summary collapse
- #agent_config ⇒ Object
- #aggregate(slow_sql, path, uri) ⇒ Object
-
#initialize(normalized_query, slow_sql, path, uri) ⇒ SqlTrace
constructor
A new instance of SqlTrace.
- #need_to_explain? ⇒ Boolean
- #need_to_obfuscate? ⇒ Boolean
- #prepare_to_send ⇒ Object
- #set_primary(slow_sql, path, uri) ⇒ Object
- #to_json(*a) ⇒ Object
Methods inherited from MethodTraceStats
#increment_count, #inspect, #record_data_point, #record_multiple_data_points
Methods inherited from StatsBase
#begin_time, #begin_time=, #end_time, #end_time=, #freeze
Methods included from Stats
#absent?, #apdex_score, #as_percentage, #as_percentage_of, #average_call_time, #average_exclusive_time, #calls_per_minute, #checked_calculation, #duration, #exclusive_time_percentage, #expand_min_max_to, #get_apdex, #is_reset?, #merge, #merge!, #merge_attributes, #midpoint, #min_time_less?, #multiply_by, #reset, #should_replace_begin_time?, #should_replace_end_time?, #stack_min_max_from, #standard_deviation, #sum_attributes, #sum_merge!, #summary, #time_percentage, #time_str, #to_s, #total_call_time_per_minute, #update_boundaries, #update_totals
Constructor Details
#initialize(normalized_query, slow_sql, path, uri) ⇒ SqlTrace
Returns a new instance of SqlTrace.
221 222 223 224 225 226 227 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 221 def initialize(normalized_query, slow_sql, path, uri) super() @params = {} #FIXME @sql_id = consistent_hash(normalized_query) set_primary slow_sql, path, uri record_data_point slow_sql.duration end |
Instance Attribute Details
#database_metric_name ⇒ Object (readonly)
Returns the value of attribute database_metric_name.
218 219 220 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 218 def database_metric_name @database_metric_name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
219 220 221 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 219 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
214 215 216 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 214 def path @path end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
217 218 219 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 217 def sql @sql end |
#sql_id ⇒ Object (readonly)
Returns the value of attribute sql_id.
216 217 218 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 216 def sql_id @sql_id end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
215 216 217 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 215 def url @url end |
Instance Method Details
#agent_config ⇒ Object
256 257 258 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 256 def agent_config NewRelic::Agent::SqlSampler.config end |
#aggregate(slow_sql, path, uri) ⇒ Object
239 240 241 242 243 244 245 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 239 def aggregate(slow_sql, path, uri) if slow_sql.duration > max_call_time set_primary slow_sql, path, uri end record_data_point slow_sql.duration end |
#need_to_explain? ⇒ Boolean
264 265 266 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 264 def need_to_explain? agent_config['explain_enabled'] end |
#need_to_obfuscate? ⇒ Boolean
260 261 262 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 260 def need_to_obfuscate? agent_config['record_sql'] == 'obfuscated' end |
#prepare_to_send ⇒ Object
247 248 249 250 251 252 253 254 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 247 def prepare_to_send begin params[:explain_plan] = @slow_sql.explain if need_to_explain? ensure NewRelic::Agent::Database.close_connections end @sql = @slow_sql.obfuscate if need_to_obfuscate? end |
#set_primary(slow_sql, path, uri) ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 229 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 # FIXME @params[:backtrace] = slow_sql.backtrace if slow_sql.backtrace end |
#to_json(*a) ⇒ Object
268 269 270 |
# File 'lib/new_relic/agent/sql_sampler.rb', line 268 def to_json(*a) [@path, @url, @sql_id, @sql, @database_metric_name, @call_count, @total_call_time, @min_call_time, @max_call_time, @params].to_json(*a) end |