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.



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/scout_apm/store.rb', line 209

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)

  @jobs = Hash.new
end

Instance Attribute Details

#db_query_metric_setObject (readonly)

Returns the value of attribute db_query_metric_set.



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

def db_query_metric_set
  @db_query_metric_set
end

#histogramsObject (readonly)

An Array of HistogramsReport



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

def histograms
  @histograms
end

#job_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



196
197
198
# File 'lib/scout_apm/store.rb', line 196

def job_traces
  @job_traces
end

#metric_setObject (readonly)

Returns the value of attribute metric_set.



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

def metric_set
  @metric_set
end

#request_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



193
194
195
# File 'lib/scout_apm/store.rb', line 193

def request_traces
  @request_traces
end

#timestampObject (readonly)

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



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

def timestamp
  @timestamp
end

Instance Method Details

#absorb_metrics!(metrics) ⇒ Object

For absorbing an array of metric => Stat records



240
241
242
243
# File 'lib/scout_apm/store.rb', line 240

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

#db_query_metrics_payloadObject



315
316
317
# File 'lib/scout_apm/store.rb', line 315

def db_query_metrics_payload
  db_query_metric_set.metrics_to_report
end

#jobsObject



307
308
309
# File 'lib/scout_apm/store.rb', line 307

def jobs
  @jobs.values
end

#merge(other) ⇒ Object

Merges another StoreReportingPeriod into this one



224
225
226
227
228
229
230
231
232
233
# File 'lib/scout_apm/store.rb', line 224

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)
  self
end

#merge_db_query_metrics!(other_metric_set) ⇒ Object



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

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

#merge_histograms!(new_histograms) ⇒ Object



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

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



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

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



247
248
249
250
# File 'lib/scout_apm/store.rb', line 247

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

#merge_slow_jobs!(new_jobs) ⇒ Object



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

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

  self
end

#merge_slow_transactions!(new_transactions) ⇒ Object



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

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



299
300
301
# File 'lib/scout_apm/store.rb', line 299

def metrics_payload
  metric_set.metrics
end

#request_countObject

Debug Helpers



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

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

#slow_jobs_payloadObject



311
312
313
# File 'lib/scout_apm/store.rb', line 311

def slow_jobs_payload
  job_traces.to_a
end

#slow_transactions_payloadObject



303
304
305
# File 'lib/scout_apm/store.rb', line 303

def slow_transactions_payload
  request_traces.to_a
end