From 6bb714422bc38c8ae70b58ac1050916dbb1aa54e Mon Sep 17 00:00:00 2001 From: Daniel Magliola Date: Tue, 25 Feb 2020 08:20:20 -0300 Subject: [PATCH] Use monotonic clock when timestamping observed values The Monotonic clock is going to be more accurate on the few cases where the distinction matters, but it's also somehow faster than `Time.now`. Signed-off-by: Daniel Magliola --- lib/prometheus/client/data_stores/direct_file_store.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/prometheus/client/data_stores/direct_file_store.rb b/lib/prometheus/client/data_stores/direct_file_store.rb index fd1886a7..717d8d5c 100644 --- a/lib/prometheus/client/data_stores/direct_file_store.rb +++ b/lib/prometheus/client/data_stores/direct_file_store.rb @@ -279,9 +279,10 @@ def write_value(key, value) init_value(key) end + now = Process.clock_gettime(Process::CLOCK_MONOTONIC) pos = @positions[key] @f.seek(pos) - @f.write([value, Time.now.to_f].pack('dd')) + @f.write([value, now].pack('dd')) @f.flush end