aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNat Lasseter <nat.lasseter@york.ac.uk>2020-03-02 14:40:40 +0000
committerNat Lasseter <nat.lasseter@york.ac.uk>2020-03-02 14:40:40 +0000
commit7b83ef5b7078bdb46f45074b5a2f96a1483e8202 (patch)
tree93857d97c64149133b678c46edd1c3ea23f760d3 /lib
parent96537e39ae2faa4c7801423055db26b86f875431 (diff)
Timestamp now reflects collected rather than reported time
Diffstat (limited to 'lib')
-rw-r--r--lib/longboat/collector.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/longboat/collector.rb b/lib/longboat/collector.rb
index 2b61c8d..adb20c3 100644
--- a/lib/longboat/collector.rb
+++ b/lib/longboat/collector.rb
@@ -4,13 +4,12 @@ module Longboat
@metrics = {}
end
- def report!(name, value, help: nil, type: nil, labels: {})
+ def report!(name, value, help: nil, type: nil, labels: {}, timestamp: Time.now)
@metrics[name] ||= {help: help, type: type}
- @metrics[name][labels] = value
+ @metrics[name][labels] = {value: value, timestamp: timestamp}
end
def metrics
- timestamp = (Time.now.to_f * 1000).to_i
res = ""
@metrics.each do |name, metric|
res << "#HELP #{name} #{metric[:help]}\n" unless metric[:help].nil?
@@ -24,7 +23,7 @@ module Longboat
labellist << "#{k}=\"#{v}\""
end
labellist = labellist.join(",")
- res << "#{name}{#{labellist}} #{value} #{timestamp}\n"
+ res << "#{name}{#{labellist}} #{value[:value]} #{(value[:timestamp].to_f * 1000).to_i}\n"
end
end
res