aboutsummaryrefslogtreecommitdiff
path: root/lib/longboat/collector.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/longboat/collector.rb')
-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