Class: ScoutApm::SlowPolicy::AgePolicy
- Defined in:
- lib/scout_apm/slow_policy/age_policy.rb
Constant Summary collapse
- POINT_MULTIPLIER_AGE =
For each minute we haven’t seen an endpoint
0.25
Instance Attribute Summary collapse
-
#last_seen ⇒ Object
readonly
A hash of Endpoint Name to the last time we stored a slow transaction for it.
Attributes inherited from Policy
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(context) ⇒ AgePolicy
constructor
A new instance of AgePolicy.
- #stored!(request) ⇒ Object
Constructor Details
#initialize(context) ⇒ AgePolicy
Returns a new instance of AgePolicy.
15 16 17 18 19 20 |
# File 'lib/scout_apm/slow_policy/age_policy.rb', line 15 def initialize(context) super zero_time = Time.now @last_seen = Hash.new { |h, k| h[k] = zero_time } end |
Instance Attribute Details
#last_seen ⇒ Object (readonly)
A hash of Endpoint Name to the last time we stored a slow transaction for it.
Defaults to a start time that is pretty close to application boot time. So the “age” of an endpoint we’ve never seen is the time the application has been running.
13 14 15 |
# File 'lib/scout_apm/slow_policy/age_policy.rb', line 13 def last_seen @last_seen end |
Instance Method Details
#call(request) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/scout_apm/slow_policy/age_policy.rb', line 22 def call(request) # How long has it been since we've seen this? age = Time.now - last_seen[request.unique_name] age / 60.0 * POINT_MULTIPLIER_AGE end |
#stored!(request) ⇒ Object
29 30 31 |
# File 'lib/scout_apm/slow_policy/age_policy.rb', line 29 def stored!(request) last_seen[request.unique_name] = Time.now end |