class Gremlin::Instruments::Base
Attributes
base_labels[RW]
docstring[RW]
name[RW]
Public Class Methods
new(name, docstring="placeholder help string", base_labels={})
click to toggle source
# 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
Public Instance Methods
cast(v)
click to toggle source
# 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()
click to toggle source
# File lib/gremlin/instruments.rb, line 14 def delete @r.del retention_key end
help()
click to toggle source
# File lib/gremlin/instruments.rb, line 61 def help @docstring end
help_string()
click to toggle source
# File lib/gremlin/instruments.rb, line 65 def help_string "# HELP #{@name} #{help}" end
node()
click to toggle source
# File lib/gremlin/instruments.rb, line 45 def node `hostname`.strip end
parse(value)
click to toggle source
# 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()
click to toggle source
# File lib/gremlin/instruments.rb, line 31 def repr parse(retention_get) end
repr_and_delete()
click to toggle source
# 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()
click to toggle source
# File lib/gremlin/instruments.rb, line 18 def retention_get @r.hgetall retention_key end
retention_key()
click to toggle source
# File lib/gremlin/instruments.rb, line 49 def retention_key nil end
type()
click to toggle source
# File lib/gremlin/instruments.rb, line 53 def type nil end
type_string()
click to toggle source
# File lib/gremlin/instruments.rb, line 57 def type_string "# TYPE #{@name} #{type}" end
values()
click to toggle source
# 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