Sha256: fe4b65bbc94c713fbe3ba9d414b0cce2185a964736fc81be8993c2d213d5eea7
Contents?: true
Size: 811 Bytes
Versions: 57
Compression:
Stored size: 811 Bytes
Contents
require 'monitor' Puppet::Util::Instrumentation.new_listener(:performance) do attr_reader :samples def initialize @samples = {}.extend(MonitorMixin) end def notify(label, event, data) return if event == :start duration = data[:finished] - data[:started] samples.synchronize do @samples[label] ||= { :count => 0, :max => 0, :min => nil, :sum => 0, :average => 0 } @samples[label][:count] += 1 @samples[label][:sum] += duration @samples[label][:max] = [ @samples[label][:max], duration ].max @samples[label][:min] = [ @samples[label][:min], duration ].reject { |val| val.nil? }.min @samples[label][:average] = @samples[label][:sum] / @samples[label][:count] end end def data samples.synchronize do @samples.dup end end end
Version data entries
57 entries across 57 versions & 3 rubygems