Class: ScoutApm::StoreReportingPeriod

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/store.rb

Overview

One period of Storage. Typically 1 minute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp, context) ⇒ StoreReportingPeriod

Returns a new instance of StoreReportingPeriod.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/scout_apm/store.rb', line 218

def initialize(timestamp, context)
  @timestamp = timestamp

  @request_traces = ScoredItemSet.new(context.config.value('max_traces'))
  @job_traces = ScoredItemSet.new(context.config.value('max_traces'))

  @histograms = []

  @metric_set = MetricSet.new
  @db_query_metric_set = DbQueryMetricSet.new(context)
  @external_service_metric_set = ExternalServiceMetricSet.new(context)

  @jobs = Hash.new
end

Instance Attribute Details

#db_query_metric_setObject (readonly)

Returns the value of attribute db_query_metric_set.



214
215
216
# File 'lib/scout_apm/store.rb', line 214

def db_query_metric_set
  @db_query_metric_set
end

#external_service_metric_setObject (readonly)

Returns the value of attribute external_service_metric_set.



216
217
218
# File 'lib/scout_apm/store.rb', line 216

def external_service_metric_set
  @external_service_metric_set
end

#histogramsObject (readonly)

An Array of HistogramsReport



206
207
208
# File 'lib/scout_apm/store.rb', line 206

def histograms
  @histograms
end

#job_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



203
204
205
# File 'lib/scout_apm/store.rb', line 203

def job_traces
  @job_traces
end

#metric_setObject (readonly)

Returns the value of attribute metric_set.



212
213
214
# File 'lib/scout_apm/store.rb', line 212

def metric_set
  @metric_set
end

#request_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



200
201
202
# File 'lib/scout_apm/store.rb', line 200

def request_traces
  @request_traces
end

#timestampObject (readonly)

A StoreReportingPeriodTimestamp representing the time that this collection of metrics is for



210
211
212
# File 'lib/scout_apm/store.rb', line 210

def timestamp
  @timestamp
end

Instance Method Details

#absorb_metrics!(metrics) ⇒ Object

For absorbing an array of metric => Stat records



251
252
253
254
# File 'lib/scout_apm/store.rb', line 251

def absorb_metrics!(metrics)
  metric_set.absorb_all(metrics)
  self
end

#db_query_metrics_payloadObject



335
336
337
# File 'lib/scout_apm/store.rb', line 335

def db_query_metrics_payload
  db_query_metric_set.metrics_to_report
end

#external_service_metrics_payloadObject



339
340
341
# File 'lib/scout_apm/store.rb', line 339

def external_service_metrics_payload
  external_service_metric_set.metrics_to_report
end

#jobsObject



327
328
329
# File 'lib/scout_apm/store.rb', line 327

def jobs
  @jobs.values
end

#merge(other) ⇒ Object

Merges another StoreReportingPeriod into this one



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/scout_apm/store.rb', line 234

def merge(other)
  self.
    merge_metrics!(other.metric_set).
    merge_slow_transactions!(other.slow_transactions_payload).
    merge_jobs!(other.jobs).
    merge_slow_jobs!(other.slow_jobs_payload).
    merge_histograms!(other.histograms).
    merge_db_query_metrics!(other.db_query_metric_set).
    merge_external_service_metrics!(other.external_service_metric_set)
  self
end

#merge_db_query_metrics!(other_metric_set) ⇒ Object



263
264
265
266
# File 'lib/scout_apm/store.rb', line 263

def merge_db_query_metrics!(other_metric_set)
  db_query_metric_set.combine!(other_metric_set)
  self
end

#merge_external_service_metrics!(other_metric_set) ⇒ Object



268
269
270
271
272
273
274
275
# File 'lib/scout_apm/store.rb', line 268

def merge_external_service_metrics!(other_metric_set)
  if other_metric_set.nil?
    logger.debug("Missing other_metric_set for merge_external_service_metrics - skipping.")
  else
    external_service_metric_set.combine!(other_metric_set)
  end
  self
end

#merge_histograms!(new_histograms) ⇒ Object



305
306
307
308
309
310
311
312
313
314
# File 'lib/scout_apm/store.rb', line 305

def merge_histograms!(new_histograms)
  new_histograms = Array(new_histograms)
  @histograms = (histograms + new_histograms).
    group_by { |histo| histo.name }.
    map { |(_, histos)|
      histos.inject { |merged, histo| merged.combine!(histo) }
    }

  self
end

#merge_jobs!(jobs) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
# File 'lib/scout_apm/store.rb', line 285

def merge_jobs!(jobs)
  Array(jobs).each do |job|
    if @jobs.has_key?(job)
      @jobs[job].combine!(job)
    else
      @jobs[job] = job
    end
  end

  self
end

#merge_metrics!(other_metric_set) ⇒ Object

For merging when you have another metric_set object Makes sure that you don’t duplicate error count records



258
259
260
261
# File 'lib/scout_apm/store.rb', line 258

def merge_metrics!(other_metric_set)
  metric_set.combine!(other_metric_set)
  self
end

#merge_slow_jobs!(new_jobs) ⇒ Object



297
298
299
300
301
302
303
# File 'lib/scout_apm/store.rb', line 297

def merge_slow_jobs!(new_jobs)
  Array(new_jobs).each do |job|
    job_traces << job
  end

  self
end

#merge_slow_transactions!(new_transactions) ⇒ Object



277
278
279
280
281
282
283
# File 'lib/scout_apm/store.rb', line 277

def merge_slow_transactions!(new_transactions)
  Array(new_transactions).each do |one_transaction|
    request_traces << one_transaction
  end

  self
end

#metrics_payloadObject

Retrieve Metrics for reporting



319
320
321
# File 'lib/scout_apm/store.rb', line 319

def metrics_payload
  metric_set.metrics
end

#request_countObject

Debug Helpers



347
348
349
350
351
# File 'lib/scout_apm/store.rb', line 347

def request_count
  metrics_payload.
    select { |meta,stats| meta.metric_name =~ /\AController/ }.
    inject(0) {|sum, (_, stat)| sum + stat.call_count }
end

#slow_jobs_payloadObject



331
332
333
# File 'lib/scout_apm/store.rb', line 331

def slow_jobs_payload
  job_traces.to_a
end

#slow_transactions_payloadObject



323
324
325
# File 'lib/scout_apm/store.rb', line 323

def slow_transactions_payload
  request_traces.to_a
end