Class: ScoutApm::StoreReportingPeriod
- Inherits:
-
Object
- Object
- ScoutApm::StoreReportingPeriod
- Defined in:
- lib/scout_apm/store.rb
Overview
One period of Storage. Typically 1 minute
Instance Attribute Summary collapse
-
#db_query_metric_set ⇒ Object
readonly
Returns the value of attribute db_query_metric_set.
-
#external_service_metric_set ⇒ Object
readonly
Returns the value of attribute external_service_metric_set.
-
#histograms ⇒ Object
readonly
An Array of HistogramsReport.
-
#job_traces ⇒ Object
readonly
A ScoredItemSet holding the “best” traces for the period.
-
#metric_set ⇒ Object
readonly
Returns the value of attribute metric_set.
-
#request_traces ⇒ Object
readonly
A ScoredItemSet holding the “best” traces for the period.
-
#timestamp ⇒ Object
readonly
A StoreReportingPeriodTimestamp representing the time that this collection of metrics is for.
Instance Method Summary collapse
-
#absorb_metrics!(metrics) ⇒ Object
For absorbing an array of metric => Stat records.
- #db_query_metrics_payload ⇒ Object
- #external_service_metrics_payload ⇒ Object
-
#initialize(timestamp, context) ⇒ StoreReportingPeriod
constructor
A new instance of StoreReportingPeriod.
- #jobs ⇒ Object
-
#merge(other) ⇒ Object
Merges another StoreReportingPeriod into this one.
- #merge_db_query_metrics!(other_metric_set) ⇒ Object
- #merge_external_service_metrics!(other_metric_set) ⇒ Object
- #merge_histograms!(new_histograms) ⇒ Object
- #merge_jobs!(jobs) ⇒ Object
-
#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.
- #merge_slow_jobs!(new_jobs) ⇒ Object
- #merge_slow_transactions!(new_transactions) ⇒ Object
-
#metrics_payload ⇒ Object
Retrieve Metrics for reporting.
-
#request_count ⇒ Object
Debug Helpers.
- #slow_jobs_payload ⇒ Object
- #slow_transactions_payload ⇒ Object
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 232 |
# File 'lib/scout_apm/store.rb', line 218 def initialize(, context) @timestamp = @context = context @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_set ⇒ Object (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_set ⇒ Object (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 |
#histograms ⇒ Object (readonly)
An Array of HistogramsReport
206 207 208 |
# File 'lib/scout_apm/store.rb', line 206 def histograms @histograms end |
#job_traces ⇒ Object (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_set ⇒ Object (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_traces ⇒ Object (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 |
#timestamp ⇒ Object (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 end |
Instance Method Details
#absorb_metrics!(metrics) ⇒ Object
For absorbing an array of metric => Stat records
257 258 259 260 |
# File 'lib/scout_apm/store.rb', line 257 def absorb_metrics!(metrics) metric_set.absorb_all(metrics) self end |
#db_query_metrics_payload ⇒ Object
341 342 343 |
# File 'lib/scout_apm/store.rb', line 341 def db_query_metrics_payload db_query_metric_set.metrics_to_report end |
#external_service_metrics_payload ⇒ Object
345 346 347 |
# File 'lib/scout_apm/store.rb', line 345 def external_service_metrics_payload external_service_metric_set.metrics_to_report end |
#jobs ⇒ Object
333 334 335 |
# File 'lib/scout_apm/store.rb', line 333 def jobs @jobs.values end |
#merge(other) ⇒ Object
Merges another StoreReportingPeriod into this one
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/scout_apm/store.rb', line 240 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
269 270 271 272 |
# File 'lib/scout_apm/store.rb', line 269 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
274 275 276 277 278 279 280 281 |
# File 'lib/scout_apm/store.rb', line 274 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
311 312 313 314 315 316 317 318 319 320 |
# File 'lib/scout_apm/store.rb', line 311 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
291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/scout_apm/store.rb', line 291 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
264 265 266 267 |
# File 'lib/scout_apm/store.rb', line 264 def merge_metrics!(other_metric_set) metric_set.combine!(other_metric_set) self end |
#merge_slow_jobs!(new_jobs) ⇒ Object
303 304 305 306 307 308 309 |
# File 'lib/scout_apm/store.rb', line 303 def merge_slow_jobs!(new_jobs) Array(new_jobs).each do |job| job_traces << job end self end |
#merge_slow_transactions!(new_transactions) ⇒ Object
283 284 285 286 287 288 289 |
# File 'lib/scout_apm/store.rb', line 283 def merge_slow_transactions!(new_transactions) Array(new_transactions).each do |one_transaction| request_traces << one_transaction end self end |
#metrics_payload ⇒ Object
Retrieve Metrics for reporting
325 326 327 |
# File 'lib/scout_apm/store.rb', line 325 def metrics_payload metric_set.metrics end |
#request_count ⇒ Object
Debug Helpers
353 354 355 356 357 |
# File 'lib/scout_apm/store.rb', line 353 def request_count metrics_payload. select { |,stats| .metric_name =~ /\AController/ }. inject(0) {|sum, (_, stat)| sum + stat.call_count } end |
#slow_jobs_payload ⇒ Object
337 338 339 |
# File 'lib/scout_apm/store.rb', line 337 def slow_jobs_payload job_traces.to_a end |
#slow_transactions_payload ⇒ Object
329 330 331 |
# File 'lib/scout_apm/store.rb', line 329 def slow_transactions_payload request_traces.to_a end |