Class: Gremlin::Instruments::Base
- Inherits:
-
Object
- Object
- Gremlin::Instruments::Base
- Defined in:
- lib/gremlin/instruments.rb
Instance Attribute Summary collapse
-
#base_labels ⇒ Object
Returns the value of attribute base_labels.
-
#docstring ⇒ Object
Returns the value of attribute docstring.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #default ⇒ Object
- #help ⇒ Object
- #help_string ⇒ Object
-
#initialize(name, docstring = "placeholder help string", base_labels = {}) ⇒ Base
constructor
A new instance of Base.
- #node ⇒ Object
- #repr ⇒ Object
- #retention_key ⇒ Object
- #type ⇒ Object
- #type_string ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(name, docstring = "placeholder help string", base_labels = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gremlin/instruments.rb', line 6 def initialize(name, docstring="placeholder help string", base_labels={}) @name = name @docstring = docstring @base_labels = base_labels @mutex = Mutex.new Redis::Client.default = Redis.new(**Gremlin.configuration.redis) @r = Redis.new(**Gremlin.configuration.redis) @values = Redis::NativeHash.find(retention_key) || Redis::NativeHash.new @values.redis = Redis.new(**Gremlin.configuration.redis) @values.key = retention_key @values.save end |
Instance Attribute Details
#base_labels ⇒ Object
Returns the value of attribute base_labels.
4 5 6 |
# File 'lib/gremlin/instruments.rb', line 4 def base_labels @base_labels end |
#docstring ⇒ Object
Returns the value of attribute docstring.
4 5 6 |
# File 'lib/gremlin/instruments.rb', line 4 def docstring @docstring end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/gremlin/instruments.rb', line 4 def name @name end |
Instance Method Details
#default ⇒ Object
36 37 38 |
# File 'lib/gremlin/instruments.rb', line 36 def default nil end |
#help ⇒ Object
40 41 42 |
# File 'lib/gremlin/instruments.rb', line 40 def help @docstring end |
#help_string ⇒ Object
44 45 46 |
# File 'lib/gremlin/instruments.rb', line 44 def help_string "# HELP #{@name} #{help}" end |
#node ⇒ Object
20 21 22 |
# File 'lib/gremlin/instruments.rb', line 20 def node `hostname`.strip end |
#repr ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/gremlin/instruments.rb', line 48 def repr { name: @name, type: type_string, help: help_string, values: values.each_with_object({}) { |(l,v), m| m[l.merge(@base_labels)] = v } } end |
#retention_key ⇒ Object
24 25 26 |
# File 'lib/gremlin/instruments.rb', line 24 def retention_key nil end |
#type ⇒ Object
28 29 30 |
# File 'lib/gremlin/instruments.rb', line 28 def type nil end |
#type_string ⇒ Object
32 33 34 |
# File 'lib/gremlin/instruments.rb', line 32 def type_string "# TYPE #{@name} #{type}" end |
#values ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gremlin/instruments.rb', line 57 def values @mutex.synchronize do @values.each_with_object({}) do |(labels, value), memo| case type when :counter memo[JSON.parse(labels)] = value.to_i when :gauge memo[JSON.parse(labels)] = value.to_f else memo[JSON.parse(labels)] = value end end end end |