Skip to content

Instantly share code, notes, and snippets.

@chendo
Created July 12, 2013 00:56
Show Gist options
  • Save chendo/5980584 to your computer and use it in GitHub Desktop.
Save chendo/5980584 to your computer and use it in GitHub Desktop.
class Metrics
extend ::NewRelic::Agent::MethodTracer
class << self
def trace_execution(*metric_names, &block)
Benchmark.realtime do
self.trace_execution_scoped(metric_names.map { |name| prepend_custom_tag(name) }, &block)
end
end
def record_metric(metric_name, value = 1)
NewRelic::Agent.record_metric(prepend_custom_tag(metric_name), value)
end
def increment_metric(metric_name, amount = 1)
NewRelic::Agent.increment_metric(prepend_custom_tag(metric_name), amount)
end
private
def prepend_custom_tag(metric_name)
"Custom/#{metric_name}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment