Simple ring middlewares for collecting request/response metrics to statsd.
Current semantic version:
[ring.middleware.statsd "1.0.0"]
(ring.middleware.statsd/setup! "statsd.host" 1234)
Record response times under timer named "resp_time"
(def app
(wrap-timer handler :resp_time))
Record counters for request methods, as "req_method.get", "req_method.post", etc
(def app
(wrap-request-method-counter handler :req_method))
Record counters for response statuses, as "resp_status.200", "resp_status.404", etc
(def app
(wrap-response-code-counter handler :resp_status))
You can customize the counter or filter which statuses are counted by passing
:key-fn
argument.
;; count only HTTP OK as "resp_status.ok". All non-200 response not counted.
(def app
(wrap-response-code-counter
handler
:resp_status
:key-fn #(if (= % 200) "ok")))
;; bucket responses into "resp_status.2XX", "resp_status.4XX", and so on
(def app
(wrap-response-code-counter
handler
:resp_status
:key-fn #(str (quot % 100) "XX")))
Copyright © 2013 Logan Linn
Distributed under the Eclipse Public License, the same as Clojure.