module Puppet::Util::Instrumentation::Instrumentable

This is the central point of all declared probes. Every class needed to declare probes should include this module and declare the methods that are subject to instrumentation:

class MyClass
  extend Puppet::Util::Instrumentation::Instrumentable

  probe :mymethod

  def mymethod
    ... this is code to be instrumented ...
  end
end

Constants

INSTRUMENTED_CLASSES

Attributes

probes[R]

Public Class Methods

clear_probes() click to toggle source
# File lib/puppet/util/instrumentation/instrumentable.rb, line 128
def self.clear_probes
  INSTRUMENTED_CLASSES.synchronize {
    INSTRUMENTED_CLASSES.clear
  }
  nil # do not leak our probes to the exterior world
end
disable_probes() click to toggle source
# File lib/puppet/util/instrumentation/instrumentable.rb, line 124
def self.disable_probes
  each_probe { |probe| probe.disable }
end
each_probe() { |probe| ... } click to toggle source
# File lib/puppet/util/instrumentation/instrumentable.rb, line 135
def self.each_probe
  INSTRUMENTED_CLASSES.synchronize {
    INSTRUMENTED_CLASSES.each_key do |klass|
      klass.probes.each { |probe| yield probe }
    end
  }
  nil # do not leak our probes to the exterior world
end
enable_probes() click to toggle source
# File lib/puppet/util/instrumentation/instrumentable.rb, line 120
def self.enable_probes
  each_probe { |probe| probe.enable }
end
probe_names() click to toggle source
# File lib/puppet/util/instrumentation/instrumentable.rb, line 114
def self.probe_names
  probe_names = []
  each_probe { |probe| probe_names << "#{probe.klass}.#{probe.method}" }
  probe_names
end
probes() click to toggle source
# File lib/puppet/util/instrumentation/instrumentable.rb, line 110
def self.probes
  @probes
end

Public Instance Methods

probe(method, options = {}) click to toggle source
Declares a new probe

It is possible to pass several options that will be later on evaluated
and sent to the instrumentation layer.

label::
  this can either be a static symbol/string or a block. If it's a block
  this one will be evaluated on every call of the instrumented method and
  should return a string or a symbol

data::
  this can be a hash or a block. If it's a block this one will be evaluated
  on every call of the instrumented method and should return a hash.

Example:

class MyClass
  extend Instrumentable

  probe :mymethod, :data => Proc.new { |args|  { :data => args[1] } }, :label => Proc.new { |args| args[0] }

  def mymethod(name, options)
  end

end
# File lib/puppet/util/instrumentation/instrumentable.rb, line 103
def probe(method, options = {})
  INSTRUMENTED_CLASSES.synchronize {
    (@probes ||= []) << Probe.new(method, self, options)
    INSTRUMENTED_CLASSES[self] = @probes
  }
end