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

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

Constructor Details

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

Instance Method Details

#defaultObject



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

def default
  0
end

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



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

def increment(labels={}, by=1)
  @mutex.synchronize do
    prev_val = get(labels.to_json) || default
    @values[labels.to_json] = prev_val + by
    @values.save
    @values[labels.to_json]
  end
end

#retention_keyObject



23
24
25
# File 'lib/gremlin/instruments/counter.rb', line 23

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

#typeObject



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

def type
  :counter
end