Skip to content

Instantly share code, notes, and snippets.

@eric
Created December 8, 2009 19:33
Show Gist options
  • Select an option

  • Save eric/251915 to your computer and use it in GitHub Desktop.

Select an option

Save eric/251915 to your computer and use it in GitHub Desktop.
# Would be nice to be part of scout internals
def counter(name, value, options = {})
current_time = Time.now
if data = memory(name)
last_time, last_value = data[:time], data[:value]
elapsed_seconds = current_time - last_time
# We won't log it if the value has wrapped or enough time hasn't
# elapsed
if value >= last_value && elapsed_seconds >= 1
result = value - last_value
case options[:per]
when :second, 'second'
result = result / elapsed_seconds.to_f
when :minute, 'minute'
result = result / elapsed_seconds.to_f / 60.0
end
result = result.to_i if options[:round]
report(name => result)
end
end
remember(name => { :time => current_time, :value => value })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment