lib/salestation/web/statsd_middleware.rb in salestation-3.5.0 vs lib/salestation/web/statsd_middleware.rb in salestation-3.5.1
- old
+ new
@@ -3,11 +3,11 @@
module Salestation
class Web < Module
class StatsdMiddleware
EXTRA_TAGS_ENV_KEY = 'salestation.statsd.tags'
- DURATION_PRECISION = 6
+ DURATION_MILLISECOND_PRECISION = 3
def initialize(app, statsd, metric:)
@app = app
@statsd = statsd
@metric = metric
@@ -30,18 +30,18 @@
"path:#{ path }",
"method:#{ method }",
"status:#{ status }"
] + env.fetch(EXTRA_TAGS_ENV_KEY, [])
- @statsd.timing(@metric, duration(from: start), tags: tags)
+ @statsd.timing(@metric, duration_ms(from: start), tags: tags)
[status, header, body]
end
private
- def duration(from:)
- (system_monotonic_time - from).round(DURATION_PRECISION)
+ def duration_ms(from:)
+ ((system_monotonic_time - from) * 1000).round(DURATION_MILLISECOND_PRECISION)
end
def system_monotonic_time
Process.clock_gettime(Process::CLOCK_MONOTONIC)
end