diff options
author | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-02 14:40:40 +0000 |
---|---|---|
committer | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-02 14:40:40 +0000 |
commit | 7b83ef5b7078bdb46f45074b5a2f96a1483e8202 (patch) | |
tree | 93857d97c64149133b678c46edd1c3ea23f760d3 | |
parent | 96537e39ae2faa4c7801423055db26b86f875431 (diff) |
Timestamp now reflects collected rather than reported time
-rw-r--r-- | lib/longboat/collector.rb | 7 | ||||
-rwxr-xr-x | longboat | 11 |
2 files changed, 8 insertions, 10 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 @@ -8,11 +8,10 @@ collector = Longboat::Collector.new jobs = Longboat::Jobs.new jobs.load(collector) -jobs.collect_every +t = jobs.collect_every + +sleep 5 +puts collector.metrics +t.exit -loop do - sleep 30 - puts collector.metrics - sleep 30 -end #Longboat::Server.serve! |