aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <nat.lasseter@york.ac.uk>2020-03-04 15:24:16 +0000
committerNat Lasseter <nat.lasseter@york.ac.uk>2020-03-04 15:24:16 +0000
commit75a2f52332fbb8176a47ba9a0ded7d0128fb5222 (patch)
tree85a22afa129385d3e8a5d410b0f94fb5c5496033
parent239829d669857a929cbd68a25dca3bd7c7b91822 (diff)
Add metric redaction
-rw-r--r--lib/longboat/collector.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/longboat/collector.rb b/lib/longboat/collector.rb
index d1a5d93..765adee 100644
--- a/lib/longboat/collector.rb
+++ b/lib/longboat/collector.rb
@@ -6,11 +6,22 @@ module Longboat
end
def report!(name, value, help: nil, type: nil, labels: {}, timestamp: Time.now)
- name = "#{@config[:metric_prefix]}#{name}"
+ name = prefix(name)
+
@metrics[name] ||= {help: help, type: type}
@metrics[name][labels] = {value: value, timestamp: timestamp}
end
+ def redact!(name, labels: nil)
+ name = prefix(name)
+
+ if labels.nil?
+ @metrics.delete(name)
+ else
+ @metrics[name].delete(labels)
+ end
+ end
+
def prometheus_metrics
res = ""
@metrics.each do |name, metric|
@@ -20,15 +31,23 @@ module Longboat
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[:value]} #{(value[:timestamp].to_f * 1000).to_i}\n"
end
end
res
end
+
+ private
+
+ def prefix(name)
+ "#{@config[:metric_prefix]}#{name}"
+ end
end
end