From 7b83ef5b7078bdb46f45074b5a2f96a1483e8202 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 2 Mar 2020 14:40:40 +0000 Subject: Timestamp now reflects collected rather than reported time --- lib/longboat/collector.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1