From d1b5795a3d260136f7ff5bbe417bf529806245d9 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Fri, 3 Feb 2017 18:22:12 +0100 Subject: [PATCH] WIP --- lib/prometheus/client/counter.rb | 2 +- lib/prometheus/client/histogram.rb | 8 ++++++++ lib/prometheus/client/metric.rb | 3 ++- spec/prometheus/client/formats/text_spec.rb | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/prometheus/client/counter.rb b/lib/prometheus/client/counter.rb index cff354b5..8309be72 100644 --- a/lib/prometheus/client/counter.rb +++ b/lib/prometheus/client/counter.rb @@ -21,7 +21,7 @@ def increment(labels = {}, by = 1) private def default(labels) - Prometheus::Client::ValueType.new(type, @name, @name, labels) + ValueType.new(type, @name, @name, labels) end end end diff --git a/lib/prometheus/client/histogram.rb b/lib/prometheus/client/histogram.rb index 0ccd3429..e3e4c9d1 100644 --- a/lib/prometheus/client/histogram.rb +++ b/lib/prometheus/client/histogram.rb @@ -30,6 +30,14 @@ def observe(value) self[bucket].increment() if value <= bucket end end + + def get() + hash = {} + each_key do |bucket| + hash[bucket] = self[bucket].get() + end + hash + end end # DEFAULT_BUCKETS are the default Histogram buckets. The default buckets diff --git a/lib/prometheus/client/metric.rb b/lib/prometheus/client/metric.rb index 69cc9c43..76baf065 100644 --- a/lib/prometheus/client/metric.rb +++ b/lib/prometheus/client/metric.rb @@ -2,6 +2,7 @@ require 'thread' require 'prometheus/client/label_set_validator' +require 'prometheus/client/valuetype' module Prometheus module Client @@ -42,7 +43,7 @@ def values private def default(labels) - ValueType.new(@name, @name, labels, nil) + ValueType.new(type, @name, @name, labels, nil) end def validate_name(name) diff --git a/spec/prometheus/client/formats/text_spec.rb b/spec/prometheus/client/formats/text_spec.rb index 14a5e504..052d55b3 100644 --- a/spec/prometheus/client/formats/text_spec.rb +++ b/spec/prometheus/client/formats/text_spec.rb @@ -1,6 +1,7 @@ # encoding: UTF-8 require 'prometheus/client/formats/text' +require 'prometheus/client/valuetype' describe Prometheus::Client::Formats::Text do let(:summary_value) do @@ -65,6 +66,11 @@ }, ), ] + metrics.each do |m| + m.values.each do |k, v| + m.values[k] = Prometheus::Client::ValueType.new(m.type, m.name, m.name, k, v) + end + end double(metrics: metrics) end