lib/pliny/metrics.rb in pliny-0.20.0 vs lib/pliny/metrics.rb in pliny-0.20.1

- old
+ new

@@ -14,18 +14,30 @@ end counts end - def measure(*names, &block) - elapsed, return_value = time_elapsed(&block) - measures = Hash[names.map { |n| ["#{Config.app_name}.#{n}", elapsed] }] + def measure(*names, **opts, &block) + if block + elapsed, return_value = time_elapsed(&block) + end + measurement = + if opts.has_key?(:value) + opts[:value] + elsif block + elapsed + else + 0 + end + + measures = Hash[names.map { |n| ["#{Config.app_name}.#{n}", measurement] }] + backends.each do |backend| report_and_catch { backend.report_measures(measures) } end - return_value + block ? return_value : measures end private def time_elapsed(&block)