From cd0f6b103553f547bc21a8447e785c31f7ce858c Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 2 Mar 2020 10:21:32 +0000 Subject: Use classes properly --- lib/longboat/metrics.rb | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 lib/longboat/metrics.rb (limited to 'lib/longboat/metrics.rb') diff --git a/lib/longboat/metrics.rb b/lib/longboat/metrics.rb deleted file mode 100644 index 58b1cbe..0000000 --- a/lib/longboat/metrics.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Longboat - module Metrics - class << self - def report!(name, value, help: nil, type: nil, labels: {}) - @metrics ||= {} - @metrics[name] ||= {help: help, type: type} - @metrics[name][labels] = value - end - - def to_s - timestamp = (Time.now.to_f * 1000).to_i - res = "" - (@metrics || {}).each do |name, metric| - res << "#HELP #{name} #{metric[:help]}\n" unless metric[:help].nil? - res << "#TYPE #{name} #{metric[:type]}\n" unless metric[:type].nil? - - metric.each do |labels, value| - next if labels == :help - next if labels == :type - labellist = [] - labels.each do |k, v| - labellist << "#{k}=\"#{v}\"" - end - labellist = labellist.join(",") - res << "#{name}{#{labellist}} #{value} #{timestamp}\n" - end - end - res - end - - def register!(collector) - @collectors ||= [] - @collectors << collector - end - - def collect! - (@collectors || []).each do |collector| - collector.collect! - end - end - end - end -end -- cgit v1.2.1