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) ⇒ StoreReportingPeriod

Returns a new instance of StoreReportingPeriod.



187
188
189
190
191
192
193
194
195
196
197
# File 'lib/scout_apm/store.rb', line 187

def initialize(timestamp)
  @timestamp = timestamp

  @request_traces = ScoredItemSet.new
  @job_traces = ScoredItemSet.new

  @histograms = []

  @metric_set = MetricSet.new
  @jobs = Hash.new
end

Instance Attribute Details

#histogramsObject (readonly)

An Array of HistogramsReport



179
180
181
# File 'lib/scout_apm/store.rb', line 179

def histograms
  @histograms
end

#job_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



176
177
178
# File 'lib/scout_apm/store.rb', line 176

def job_traces
  @job_traces
end

#metric_setObject (readonly)

Returns the value of attribute metric_set.



185
186
187
# File 'lib/scout_apm/store.rb', line 185

def metric_set
  @metric_set
end

#request_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



173
174
175
# File 'lib/scout_apm/store.rb', line 173

def request_traces
  @request_traces
end

#timestampObject (readonly)

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



183
184
185
# File 'lib/scout_apm/store.rb', line 183

def timestamp
  @timestamp
end

Instance Method Details

#absorb_metrics!(metrics) ⇒ Object

For absorbing an array of metric => Stat records



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

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

#jobsObject



277
278
279
# File 'lib/scout_apm/store.rb', line 277

def jobs
  @jobs.values
end

#merge(other) ⇒ Object

Merges another StoreReportingPeriod into this one



200
201
202
203
204
205
206
207
208
# File 'lib/scout_apm/store.rb', line 200

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

#merge_histograms!(new_histograms) ⇒ Object



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

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



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

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



222
223
224
225
# File 'lib/scout_apm/store.rb', line 222

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

#merge_slow_jobs!(new_jobs) ⇒ Object



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

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

  self
end

#merge_slow_transactions!(new_transactions) ⇒ Object



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

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



269
270
271
# File 'lib/scout_apm/store.rb', line 269

def metrics_payload
  metric_set.metrics
end

#request_countObject

Debug Helpers



289
290
291
292
293
# File 'lib/scout_apm/store.rb', line 289

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

#slow_jobs_payloadObject



281
282
283
# File 'lib/scout_apm/store.rb', line 281

def slow_jobs_payload
  job_traces.to_a
end

#slow_transactions_payloadObject



273
274
275
# File 'lib/scout_apm/store.rb', line 273

def slow_transactions_payload
  request_traces.to_a
end