Skip to content

Instantly share code, notes, and snippets.

@halgari
Created October 26, 2017 16:24
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 halgari/71dd5cfd8234a982a11e48d2aac003b0 to your computer and use it in GitHub Desktop.
Save halgari/71dd5cfd8234a982a11e48d2aac003b0 to your computer and use it in GitHub Desktop.
(def ^:dynamic *counters*)
(defn new-counter [name]
"Creates a pair of LongAdders"
...)
(defn get-counter [name]
(if-let [ctr (get *counter* name]
ctr
(let [c (new-counter name)
(set! *counters* (assoc *counters* c))
c)))
(defn record-value [k v]
(record-counter (get-counter k) v))
; ^^ Part of our existing metrics library
(defn on-event
[k v]
(when *counters*
(record-value k v)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment