Class: Gremlin::Instruments::Counter

Inherits:
Base
  • Object
show all
Defined in:
lib/gremlin/instruments/counter.rb

Instance Attribute Summary

Attributes inherited from Base

#base_labels, #docstring, #name

Instance Method Summary collapse

Methods inherited from Base

#help, #help_string, #initialize, #node, #repr, #type_string, #values

Constructor Details

This class inherits a constructor from Gremlin::Instruments::Base

Instance Method Details

#defaultObject



12
13
14
# File 'lib/gremlin/instruments/counter.rb', line 12

def default
  0
end

#get(labels = {}) ⇒ Object



24
25
26
27
28
# File 'lib/gremlin/instruments/counter.rb', line 24

def get(labels={})
  @values.reload!
  v = @values[labels.to_json]
  v.to_i
end

#increment(labels = {}, by = 1) ⇒ Object



6
7
8
9
10
# File 'lib/gremlin/instruments/counter.rb', line 6

def increment(labels={}, by=1)
  @mutex.synchronize do
    @r.hincrby retention_key, labels.to_json, by
  end
end

#retention_keyObject



20
21
22
# File 'lib/gremlin/instruments/counter.rb', line 20

def retention_key
  "gremlin_prometheus_#{node}_metrics_counter_#{name}"
end

#typeObject



16
17
18
# File 'lib/gremlin/instruments/counter.rb', line 16

def type
  :counter
end