diff --git a/lib/prometheus/client/data_stores/direct_file_store.rb b/lib/prometheus/client/data_stores/direct_file_store.rb index bf9d6d22..1c09dc4d 100644 --- a/lib/prometheus/client/data_stores/direct_file_store.rb +++ b/lib/prometheus/client/data_stores/direct_file_store.rb @@ -114,8 +114,7 @@ def increment(labels:, by: 1) key = store_key(labels) in_process_sync do - value = internal_store.read_value(key) - internal_store.write_value(key, value + by.to_f) + internal_store.increment_value(key, by.to_f) end end @@ -286,6 +285,21 @@ def write_value(key, value) @f.flush end + def increment_value(key, by) + if !@positions.has_key?(key) + init_value(key) + end + + pos = @positions[key] + @f.seek(pos) + value = @f.read(8).unpack('d')[0] + + now = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @f.seek(-8, :CUR) + @f.write([value + by, now].pack('dd')) + @f.flush + end + def close @f.close end