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
- #cast(v) ⇒ Object
- #delete ⇒ Object
- #help ⇒ Object
- #help_string ⇒ Object
-
#initialize(name, docstring = "placeholder help string", base_labels = {}) ⇒ Base
constructor
A new instance of Base.
- #node ⇒ Object
- #parse(value) ⇒ Object
- #repr ⇒ Object
- #repr_and_delete ⇒ Object
- #retention_get ⇒ 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 |
# File 'lib/gremlin/instruments.rb', line 6 def initialize(name, docstring="placeholder help string", base_labels={}) @name = name @docstring = docstring @base_labels = base_labels @r = Redis.new(**Gremlin.configuration.redis) 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
#cast(v) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gremlin/instruments.rb', line 69 def cast(v) case type when :counter v.to_i when :gauge v.to_f else v end end |
#delete ⇒ Object
14 15 16 |
# File 'lib/gremlin/instruments.rb', line 14 def delete @r.del retention_key end |
#help ⇒ Object
61 62 63 |
# File 'lib/gremlin/instruments.rb', line 61 def help @docstring end |
#help_string ⇒ Object
65 66 67 |
# File 'lib/gremlin/instruments.rb', line 65 def help_string "# HELP #{@name} #{help}" end |
#node ⇒ Object
45 46 47 |
# File 'lib/gremlin/instruments.rb', line 45 def node `hostname`.strip end |
#parse(value) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/gremlin/instruments.rb', line 22 def parse(value) { name: @name, type: type_string, help: help_string, values: value.each_with_object({}) { |(l,v), m| m[JSON.parse(l).merge(@base_labels)] = cast(v) } } end |
#repr ⇒ Object
31 32 33 |
# File 'lib/gremlin/instruments.rb', line 31 def repr parse(retention_get) end |
#repr_and_delete ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/gremlin/instruments.rb', line 35 def repr_and_delete val = nil @r.pipelined do val = retention_get @r.del retention_key end v = parse(val.value) return v end |
#retention_get ⇒ Object
18 19 20 |
# File 'lib/gremlin/instruments.rb', line 18 def retention_get @r.hgetall retention_key end |
#retention_key ⇒ Object
49 50 51 |
# File 'lib/gremlin/instruments.rb', line 49 def retention_key nil end |
#type ⇒ Object
53 54 55 |
# File 'lib/gremlin/instruments.rb', line 53 def type nil end |
#type_string ⇒ Object
57 58 59 |
# File 'lib/gremlin/instruments.rb', line 57 def type_string "# TYPE #{@name} #{type}" end |
#values ⇒ Object
80 81 82 83 84 |
# File 'lib/gremlin/instruments.rb', line 80 def values retention_get.each_with_object({}) do |(labels, value), memo| memo[JSON.parse(labels)] = cast(value) end end |