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
-
#probes ⇒ Object
readonly
Returns the value of attribute probes.
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)
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_probes ⇒ Object
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_probes ⇒ Object
124 125 126 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 124 def self.disable_probes each_probe { |probe| probe.disable } end |
.each_probe ⇒ Object
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_probes ⇒ Object
120 121 122 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 120 def self.enable_probes each_probe { |probe| probe.enable } end |
.probe_names ⇒ Object
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 |
.probes ⇒ Object
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, )
end
end
103 104 105 106 107 108 |
# File 'lib/vendor/puppet/util/instrumentation/instrumentable.rb', line 103 def probe(method, = {}) INSTRUMENTED_CLASSES.synchronize { (@probes ||= []) << Probe.new(method, self, ) INSTRUMENTED_CLASSES[self] = @probes } end |