1

In my handler I have the following defined:

(def reg (new-registry))

(def app (-> app-routes 
         (expose-metrics-as-json)
         (instrument reg)))

If I go to /metrics I only see an empty json object. What am I missing? Also, the documetation is not clear as to how I can report on the console, it seems report-to-console which is in the documentation is not used any more, instead there are reporters but I cannot find any documentation as to how you use reporters.

EDIT:

I have seen that metrics are being added and recorded by looking at this:

(meters/rates ((all-metrics reg) "ring.responses.rate.2xx"))

And the results are as expected, something like:

{1 0.06325196458537237, 5 0.01824839591203641, 15 0.006466051961211013, :total 6}

So it seems that although expose-metrics-as-json is creating an endpoint, the metrics are not getting added to it.

shmish111
  • 3,697
  • 5
  • 30
  • 52

2 Answers2

3

You are not passing the registry to expose-metrics-as-json. It falls back to the default registry.

In your threading expression, try changing the second line so that it reads:

(def app (-> app-routes
             (expose-metrics-as-json "/metrics" reg)
             (instrument reg)))
Leon Grapenthin
  • 9,246
  • 24
  • 37
  • I tried this just after I posted the question but it did not work. I pasted your code in. The middlewares must be getting picked up because the metrics url is exposed, it just doesn't have any metrics. – shmish111 Jul 23 '14 at 12:28
3

Ha! I found that this is actually a bug in the code. https://github.com/sjl/metrics-clojure/blob/master/metrics-clojure-ring/src/metrics/ring/expose.clj

([handler uri registry]
    (expose-metrics-as-json handler uri default-registry {:pretty-print? false}))

This ignores the registry parameter. I got things to work by using

(expose-metrics-as-json "/metrics" reg {:pretty-print? false})

I will fix and create a pull request.

shmish111
  • 3,697
  • 5
  • 30
  • 52