Module: Puppet::Util::Instrumentation::Instrumentable

Included in:
Indirector::Indirection
Defined in:
lib/vendor/puppet/util/instrumentation/instrumentable.rb

Overview

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

Defined Under Namespace

Classes: Probe

Constant Summary collapse

INSTRUMENTED_CLASSES =
{}.extend(MonitorMixin)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#probesObject (readonly)

Returns the value of attribute probes.



20
21
22
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 20

def probes
  @probes
end

Class Method Details

.clear_probesObject



128
129
130
131
132
133
# File 'lib/vendor/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_probesObject



124
125
126
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 124

def self.disable_probes
  each_probe { |probe| probe.disable }
end

.each_probeObject



135
136
137
138
139
140
141
142
# File 'lib/vendor/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_probesObject



120
121
122
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 120

def self.enable_probes
  each_probe { |probe| probe.enable }
end

.probe_namesObject



114
115
116
117
118
# File 'lib/vendor/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

.probesObject



110
111
112
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 110

def self.probes
  @probes
end

Instance Method Details

#probe(method, options = {}) ⇒ Object

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


103
104
105
106
107
108
# File 'lib/vendor/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