Skip to content

Instantly share code, notes, and snippets.

@orb
Created May 14, 2014 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orb/d2075fbdb49e29276c40 to your computer and use it in GitHub Desktop.
Save orb/d2075fbdb49e29276c40 to your computer and use it in GitHub Desktop.
(defn find-timer [timer-name]
(timers/timer ["APPNAME" "timer" (name timer-name)]))
(defmacro with-timer [timer-name & body]
`(let [timer# (find-timer ~timer-name)]
(timers/time! timer#
(do ~@body))))
@clifton
Copy link

clifton commented May 14, 2014

On our diversion onto metrics last night, we forgot to circle back to look at the timer. Here's slightly modified version: https://gist.github.com/orb/d207...­

This basically wraps a named timer which (through code not shown here) creates a timer metric and queues it to be sent to Riemann. There's nothing magical here except the point I was making about being able to nREPL to the server. If we are trying to live-debug a performance issue, I can connect to the server and wrap the code I'm interested in a with-timer. We'll immediately get live metrics into Riemann and then into elastic search for those pretty charts I showed in kibana. When we're done, I can remove the with-timer.

I find this brilliant. It doesn't require making a lot of toggle-able metrics in advance. It doesn't require any tooling fancier than nREPL. And, it doesn't require any server downtime.

@clifton
Copy link

clifton commented May 14, 2014

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment