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.



168
169
170
171
172
173
174
175
176
# File 'lib/scout_apm/store.rb', line 168

def initialize(timestamp)
  @timestamp = timestamp

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

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

Instance Attribute Details

#job_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



160
161
162
# File 'lib/scout_apm/store.rb', line 160

def job_traces
  @job_traces
end

#metric_setObject (readonly)

Returns the value of attribute metric_set.



166
167
168
# File 'lib/scout_apm/store.rb', line 166

def metric_set
  @metric_set
end

#request_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



157
158
159
# File 'lib/scout_apm/store.rb', line 157

def request_traces
  @request_traces
end

#timestampObject (readonly)

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



164
165
166
# File 'lib/scout_apm/store.rb', line 164

def timestamp
  @timestamp
end

Instance Method Details

#absorb_metrics!(metrics) ⇒ Object

For absorbing an array of metric => Stat records



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

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

#jobsObject



244
245
246
# File 'lib/scout_apm/store.rb', line 244

def jobs
  @jobs.values
end

#merge(other) ⇒ Object

Merges another StoreReportingPeriod into this one



179
180
181
182
183
184
185
186
# File 'lib/scout_apm/store.rb', line 179

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

#merge_jobs!(jobs) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
# File 'lib/scout_apm/store.rb', line 213

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



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

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

#merge_slow_jobs!(new_jobs) ⇒ Object



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

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

  self
end

#merge_slow_transactions!(new_transactions) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/scout_apm/store.rb', line 205

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



236
237
238
# File 'lib/scout_apm/store.rb', line 236

def metrics_payload
  metric_set.metrics
end

#request_countObject

Debug Helpers



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

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

#slow_jobs_payloadObject



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

def slow_jobs_payload
  job_traces.to_a
end

#slow_transactions_payloadObject



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

def slow_transactions_payload
  request_traces.to_a
end