class Pencil::Models::Base

Attributes

name[R]

Public Class Methods

all() click to toggle source
# File lib/pencil/models/base.rb, line 23
def self.all
  return @@objects[self.name].values
end
each() { |k, v| ... } click to toggle source
# File lib/pencil/models/base.rb, line 18
def self.each(&block)
  h = @@objects[self.name] rescue {}
  h.each { |k, v| yield(k, v) }
end
find(name) click to toggle source
# File lib/pencil/models/base.rb, line 14
def self.find(name)
  return @@objects[self.name][name] rescue []
end
new(name, params={}) click to toggle source
# File lib/pencil/models/base.rb, line 7
def initialize(name, params={})
  @name = name
  @match_name = name
  @params = params
  @@objects[self.class.to_s][name] = self
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/pencil/models/base.rb, line 53
def <=>(other)
  return to_s <=> other.to_s
end
[](key) click to toggle source
# File lib/pencil/models/base.rb, line 27
def [](key)
  return @params[key] rescue []
end
compose_metric(m, c, h) click to toggle source

compose a metric using a :metric_format format string with %c for metric, %c for cluster, and %h for host

# File lib/pencil/models/base.rb, line 63
def compose_metric (m, c, h)
  @params[:metric_format].dup.gsub("%m", m).gsub("%c", c).gsub("%h", h)
end
compose_metric2(m, c, h) click to toggle source

used to make sure partial metrics are not considered e.g. foo.bar.baz.colo1.host1 but not

foo.bar.baz.subkey.subkey2[.colo1.host1]

where the latter is returned by the graphite expand api but not as a full metric essentially equivalent to matching like /[:METRIC:]$/

# File lib/pencil/models/base.rb, line 73
def compose_metric2 (m, c, h)
  compose_metric(m, c, h) + ".*"
end
match(glob) click to toggle source
# File lib/pencil/models/base.rb, line 31
def match(glob)
  return true if glob == '*'
  # convert glob to a regular expression
  glob_re = /^#{Regexp.escape(glob).gsub('\*', '.*').gsub('\#', '\d+')}$/
  return @match_name.match(glob_re)
end
multi_match(globs) click to toggle source
# File lib/pencil/models/base.rb, line 38
def multi_match(globs)
  ret = false

  globs.each do |glob|
    ret = match(glob)
    break if ret
  end

  return ret
end
to_s() click to toggle source
# File lib/pencil/models/base.rb, line 49
def to_s
  return @name
end
update_params(hash) click to toggle source
# File lib/pencil/models/base.rb, line 57
def update_params(hash)
  @params.merge!(hash)
end