diff options
-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! |