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.



147
148
149
150
151
152
153
154
155
# File 'lib/scout_apm/store.rb', line 147

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



139
140
141
# File 'lib/scout_apm/store.rb', line 139

def job_traces
  @job_traces
end

#metric_setObject (readonly)

Returns the value of attribute metric_set.



145
146
147
# File 'lib/scout_apm/store.rb', line 145

def metric_set
  @metric_set
end

#request_tracesObject (readonly)

A ScoredItemSet holding the “best” traces for the period



136
137
138
# File 'lib/scout_apm/store.rb', line 136

def request_traces
  @request_traces
end

#timestampObject (readonly)

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



143
144
145
# File 'lib/scout_apm/store.rb', line 143

def timestamp
  @timestamp
end

Instance Method Details

#absorb_metrics!(metrics) ⇒ Object

For absorbing an array of metric => Stat records



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

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

#jobsObject



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

def jobs
  @jobs.values
end

#merge(other) ⇒ Object

Merges another StoreReportingPeriod into this one



158
159
160
161
162
163
164
165
# File 'lib/scout_apm/store.rb', line 158

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



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/scout_apm/store.rb', line 192

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



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

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

#merge_slow_jobs!(new_jobs) ⇒ Object



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

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

  self
end

#merge_slow_transactions!(new_transactions) ⇒ Object



184
185
186
187
188
189
190
# File 'lib/scout_apm/store.rb', line 184

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



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

def metrics_payload
  metric_set.metrics
end

#request_countObject

Debug Helpers



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

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

#slow_jobs_payloadObject



227
228
229
# File 'lib/scout_apm/store.rb', line 227

def slow_jobs_payload
  job_traces.to_a
end

#slow_transactions_payloadObject



219
220
221
# File 'lib/scout_apm/store.rb', line 219

def slow_transactions_payload
  request_traces.to_a
end