Class: NewRelic::Agent::SqlTrace
- Inherits:
-
Stats
- Object
- Stats
- NewRelic::Agent::SqlTrace
show all
- Includes:
- Coerce
- Defined in:
- lib/new_relic/agent/sql_sampler.rb
Constant Summary
Constants inherited
from Stats
NewRelic::Agent::Stats::SKIP_MARSHALLING
Instance Attribute Summary collapse
Attributes inherited from Stats
#call_count, #max_call_time, #min_call_time, #sum_of_squares, #total_call_time, #total_exclusive_time
Instance Method Summary
collapse
Methods included from Coerce
boolean_int!, float, float!, int, int!, int_or_nil, log_failure, scalar, string, value_or_nil
Methods inherited from Stats
#==, #hash_merge, #increment_count, #inspect_full, #is_reset?, #marshal_dump, #marshal_load, #merge, #merge!, #record, #record_apdex, #record_data_point, #reset, #to_json, #to_s
Constructor Details
#initialize(normalized_query, slow_sql, path, uri) ⇒ SqlTrace
Returns a new instance of SqlTrace.
266
267
268
269
270
271
272
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 266
def initialize(normalized_query, slow_sql, path, uri)
super()
@params = slow_sql.base_params
@sql_id = consistent_hash(normalized_query)
set_primary(slow_sql, path, uri)
record_data_point(float(slow_sql.duration))
end
|
Instance Attribute Details
#database_metric_name ⇒ Object
262
263
264
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 262
def database_metric_name
@database_metric_name
end
|
#params ⇒ Object
263
264
265
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 263
def params
@params
end
|
#path ⇒ Object
258
259
260
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 258
def path
@path
end
|
#slow_sql ⇒ Object
264
265
266
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 264
def slow_sql
@slow_sql
end
|
#sql ⇒ Object
261
262
263
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 261
def sql
@sql
end
|
#sql_id ⇒ Object
260
261
262
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 260
def sql_id
@sql_id
end
|
#url ⇒ Object
259
260
261
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 259
def url
@url
end
|
Instance Method Details
#aggregate(slow_sql, path, uri) ⇒ Object
283
284
285
286
287
288
289
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 283
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) ⇒ Object
291
292
293
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 291
def aggregate_trace(trace)
aggregate(trace.slow_sql, trace.path, trace.url)
end
|
#need_to_explain? ⇒ Boolean
305
306
307
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 305
def need_to_explain?
Agent.config[:'slow_sql.explain_enabled']
end
|
#need_to_obfuscate? ⇒ Boolean
301
302
303
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 301
def need_to_obfuscate?
Agent.config[:'slow_sql.record_sql'].to_s == 'obfuscated'
end
|
#prepare_to_send ⇒ Object
295
296
297
298
299
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 295
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) ⇒ Object
274
275
276
277
278
279
280
281
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 274
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) ⇒ Object
311
312
313
314
315
316
317
318
319
320
321
322
|
# File 'lib/new_relic/agent/sql_sampler.rb', line 311
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
|