Create a gist now

Instantly share code, notes, and snippets.

@orb /timer.clj
Created May 14, 2014

(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))))

On our diversion onto metrics last night, we forgot to circle back to look at the timer. Here's slightly modified version:­

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.



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