Class: Amigo::Autoscaler::Checkers::WebLatency::Middleware
- Inherits:
-
Object
- Object
- Amigo::Autoscaler::Checkers::WebLatency::Middleware
- Defined in:
- lib/amigo/autoscaler/checkers/web_latency.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, redis:, threshold: 0.08, namespace: NAMESPACE) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, redis:, threshold: 0.08, namespace: NAMESPACE) ⇒ Middleware
Returns a new instance of Middleware.
69 70 71 72 73 74 |
# File 'lib/amigo/autoscaler/checkers/web_latency.rb', line 69 def initialize(app, redis:, threshold: 0.08, namespace: NAMESPACE) @app = app @redis = redis @threshold = threshold @namespace = namespace end |
Instance Method Details
#call(env) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/amigo/autoscaler/checkers/web_latency.rb', line 76 def call(env) start = Process.clock_gettime(Process::CLOCK_MONOTONIC) status, headers, body = @app.call(env) duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start if duration > @threshold begin WebLatency.set_latency( redis: @redis, namespace: @namespace, at: Time.now, duration:, ) rescue StandardError => e Amigo.log(nil, :error, "web_latency_error", exception: e) end end [status, headers, body] end |