Module: Puppet::Util::Instrumentation::Instrumentable
- Included in:
- Indirector::Indirection
- Defined in:
- lib/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 =
{}
Instance Attribute Summary collapse
- #probes ⇒ Object readonly
Class Method Summary collapse
- .clear_probes ⇒ Object
- .disable_probes ⇒ Object
- .each_probe ⇒ Object
- .enable_probes ⇒ Object
- .probe_names ⇒ Object
- .probes ⇒ Object
Instance Method Summary collapse
-
#probe(method, options = {}) ⇒ Object
Declares a new probe.
Instance Attribute Details
#probes ⇒ Object (readonly)
19 20 21 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 19 def probes @probes end |
Class Method Details
.clear_probes ⇒ Object
125 126 127 128 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 125 def self.clear_probes INSTRUMENTED_CLASSES.clear nil # do not leak our probes to the exterior world end |
.disable_probes ⇒ Object
121 122 123 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 121 def self.disable_probes each_probe { |probe| probe.disable } end |
.each_probe ⇒ Object
130 131 132 133 134 135 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 130 def self.each_probe 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 ⇒ Object
117 118 119 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 117 def self.enable_probes each_probe { |probe| probe.enable } end |
.probe_names ⇒ Object
111 112 113 114 115 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 111 def self.probe_names probe_names = [] each_probe { |probe| probe_names << "#{probe.klass}.#{probe.method}" } probe_names end |
.probes ⇒ Object
107 108 109 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 107 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, )
end
end
102 103 104 105 |
# File 'lib/puppet/util/instrumentation/instrumentable.rb', line 102 def probe(method, = {}) (@probes ||= []) << Probe.new(method, self, ) INSTRUMENTED_CLASSES[self] = @probes end |