Last active
August 29, 2015 14:06
-
-
Save kornysietsma/0a5325398a8d8ecb3dad to your computer and use it in GitHub Desktop.
instrumenting functions via graphite and robert-hooke
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn graphiteisze-path | |
"Graphite uses a dot (.) as a separator. Whisper stores metrics on disk by name, so we cannot have slashes in the metric name" | |
[path] | |
(clojure.string/replace path #"[/\.]" "_")) | |
(defn timed-hook-fn | |
[metric-registry group type name] | |
(let [timer (timer metric-registry [(graphiteisze-path group) (graphiteisze-path type) (graphiteisze-path name)])] | |
(fn [f & args] | |
(time-fn! timer #(apply f args))))) | |
(defn- with-timer [metric-registry ns fname f & args] | |
(time! | |
(timer metric-registry ["functions" (graphiteisze-path (name (ns-name ns))) (graphiteisze-path fname)]) (apply f args))) | |
(defn- instrument-with-timer! [metric-registry fn] | |
(let [{:keys [ns name]} (meta fn)] | |
(rh/add-hook fn (timed-hook-fn metric-registry "functions" ns name)))) | |
(defn instrument-functions! [metric-registry] | |
(dorun (map (partial instrument-with-timer! metric-registry) | |
[#'my-fn-namespace/my-fn-name]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment