Class: Protor::Registry
- Inherits:
-
Object
- Object
- Protor::Registry
- Defined in:
- lib/protor/registry.rb
Constant Summary collapse
- DEFAULT_BUCKET =
[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10].freeze
Instance Attribute Summary collapse
-
#families ⇒ Object
readonly
Returns the value of attribute families.
Instance Method Summary collapse
- #counter(metric_name, value, labels = {}) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #gauge(metric_name, value, labels = {}) ⇒ Object
- #histogram(metric_name, value, labels = {}, buckets = DEFAULT_BUCKET) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
10 11 12 |
# File 'lib/protor/registry.rb', line 10 def initialize @families = {} end |
Instance Attribute Details
#families ⇒ Object (readonly)
Returns the value of attribute families.
6 7 8 |
# File 'lib/protor/registry.rb', line 6 def families @families end |
Instance Method Details
#counter(metric_name, value, labels = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/protor/registry.rb', line 14 def counter(metric_name, value, labels = {}) labels = stringify(labels) fam = family(metric_name, :counter) if (entry = fam[labels]) entry.value += value else fam[labels] = Entry.new(metric_name, :c, value, labels) end end |
#each ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/protor/registry.rb', line 48 def each families.each_value do |family| if family.type == :histogram family.each{ |arr| arr.each{ |e| yield(e) }} else family.each{ |e| yield(e) } end end end |
#empty? ⇒ Boolean
62 63 64 |
# File 'lib/protor/registry.rb', line 62 def empty? families.empty? end |
#gauge(metric_name, value, labels = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/protor/registry.rb', line 25 def gauge(metric_name, value, labels = {}) labels = stringify(labels) fam = family(metric_name, :gauge) if (entry = fam[labels]) entry.value = value else fam[labels] = Entry.new(metric_name, :g, value, labels) end end |
#histogram(metric_name, value, labels = {}, buckets = DEFAULT_BUCKET) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/protor/registry.rb', line 36 def histogram(metric_name, value, labels = {}, buckets = DEFAULT_BUCKET) labels = stringify(labels) fam = family(metric_name, :histogram) entry = Entry.new(metric_name, :h, value, labels, buckets) if (array = fam[labels]) array << entry else fam[labels] = [ entry ] end end |
#reset ⇒ Object
58 59 60 |
# File 'lib/protor/registry.rb', line 58 def reset @families = {} end |