Class: ScoutApm::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/store.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Store

Returns a new instance of Store.



6
7
8
9
10
11
# File 'lib/scout_apm/store.rb', line 6

def initialize(context)
  @context = context
  @mutex = Mutex.new
  @reporting_periods = Hash.new { |h,k| h[k] = StoreReportingPeriod.new(k, @context) }
  @samplers = []
end

Instance Method Details

#add_sampler(sampler_klass) ⇒ Object

Sampler support



115
116
117
# File 'lib/scout_apm/store.rb', line 115

def add_sampler(sampler_klass)
  @samplers << sampler_klass.new(@context)
end

#current_timestampObject



13
14
15
# File 'lib/scout_apm/store.rb', line 13

def current_timestamp
  StoreReportingPeriodTimestamp.new(Time.now)
end

#tick!Object

For each tick (minute), be sure we have a reporting period, and that samplers are run for it.



95
96
97
98
# File 'lib/scout_apm/store.rb', line 95

def tick!
  rp = current_period
  collect_samplers(rp)
end

#track!(metrics, options = {}) ⇒ Object

Save newly collected metrics



32
33
34
35
36
37
# File 'lib/scout_apm/store.rb', line 32

def track!(metrics, options={})
  @mutex.synchronize {
    period = find_period(options[:timestamp])
    period.absorb_metrics!(metrics)
  }
end

#track_db_query_metrics!(db_query_metric_set, options = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/scout_apm/store.rb', line 46

def track_db_query_metrics!(db_query_metric_set, options={})
  @mutex.synchronize {
    period = find_period(options[:timestamp])
    period.merge_db_query_metrics!(db_query_metric_set)
  }
end

#track_histograms!(histograms, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/scout_apm/store.rb', line 39

def track_histograms!(histograms, options={})
  @mutex.synchronize {
    period = find_period(options[:timestamp])
    period.merge_histograms!(histograms)
  }
end

#track_job!(job) ⇒ Object



68
69
70
71
72
73
# File 'lib/scout_apm/store.rb', line 68

def track_job!(job)
  return if job.nil?
  @mutex.synchronize {
    current_period.merge_jobs!(Array(job))
  }
end

#track_one!(type, name, value, options = {}) ⇒ Object



53
54
55
56
57
58
# File 'lib/scout_apm/store.rb', line 53

def track_one!(type, name, value, options={})
  meta = MetricMeta.new("#{type}/#{name}")
  stat = MetricStats.new(false)
  stat.update!(value)
  track!({meta => stat}, options)
end

#track_slow_job!(job) ⇒ Object



75
76
77
78
79
80
# File 'lib/scout_apm/store.rb', line 75

def track_slow_job!(job)
  return if job.nil?
  @mutex.synchronize {
    current_period.merge_slow_jobs!(Array(job))
  }
end

#track_slow_transaction!(slow_transaction) ⇒ Object

Save a new slow transaction



61
62
63
64
65
66
# File 'lib/scout_apm/store.rb', line 61

def track_slow_transaction!(slow_transaction)
  return unless slow_transaction
  @mutex.synchronize {
    current_period.merge_slow_transactions!(slow_transaction)
  }
end

#write_to_layaway(layaway, force = false) ⇒ Object

Take each completed reporting_period, and write it to the layaway passed

force - a boolean argument that forces this function to write current-minute metrics. Useful when we are shutting down the agent during a restart.



87
88
89
90
91
92
# File 'lib/scout_apm/store.rb', line 87

def write_to_layaway(layaway, force=false)
  logger.debug("Writing to layaway#{" (Forced)" if force}")

  @reporting_periods.select { |time, rp| force || (time.timestamp < current_timestamp.timestamp) }.
                     each   { |time, rp| write_reporting_period(layaway, time, rp) }
end