Skip to content

Commit 4c00fe9

Browse files
author
Daniel Magliola
committed
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 <danielmagliola@gocardless.com>
1 parent 31f0895 commit 4c00fe9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/prometheus/client/data_stores/direct_file_store.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ def write_value(key, value)
279279
init_value(key)
280280
end
281281

282+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
282283
pos = @positions[key]
283284
@f.seek(pos)
284-
@f.write([value, Time.now.to_f].pack('dd'))
285+
@f.write([value, now].pack('dd'))
285286
@f.flush
286287
end
287288

0 commit comments

Comments
 (0)