# metrics-clojure / docs / source / ring.rst

 Steve Losh 0a3a634 2012-03-09 Steve Losh ff65daf 2012-03-17 Steve Losh 0a3a634 2012-03-09 Steve Losh 83bf0a9 2012-03-17 Steve Losh 0a3a634 2012-03-09 Steve Losh ff65daf 2012-03-17 Steve Losh 0a3a634 2012-03-09 Steve Losh a3a2353 2012-03-10 Steve Losh 0a3a634 2012-03-09 Steve Losh 0589350 2012-03-09 Steve Losh a3a2353 2012-03-10 Steve Losh 0589350 2012-03-09   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 Extras for Ring =============== metrics-clojure contains some extra glue code you can use with your Ring _ apps. Installation ------------ The extra Ring-related functionality is in a separate metrics-clojure-ring library so you don't have to install it unless you want it. To install it, add this to your project.clj's dependencies:: [metrics-clojure-ring "0.8.0"] **Note:** the versions of metrics-clojure and metrics-clojure-ring should always be the same. Exposing Metrics as JSON ------------------------ You can expose your app's metrics as JSON by using the expose-metrics-as-json middleware:: (use '[metrics.ring.expose :only (expose-metrics-as-json)]) (def app (expose-metrics-as-json app)) This will add a /metrics/ URL that will show all the metrics for the app. The trailing slash is required. This middleware works great with Noir, too. If you want to use a different endpoint you can pass it as a parameter:: (use '[metrics.ring.expose :only (expose-metrics-as-json)]) (def app (expose-metrics-as-json app "/admin/stats/")) **WARNING**: this URL will not be protected by a username or password in any way (yet), so if you have sensitive metrics you might want to think twice about using it (or protect it yourself). JSON Format ~~~~~~~~~~~ Here's an example of the JSON format:: { "default.default.sample-metric": { "type": "counter", "value": 10 } } The JSON is an object that maps metric names to their data. Each metric object will have a type attribute. The rest of the attributes will depend on the type of metric. **TODO**: Document each individual type. Instrumenting a Ring App ------------------------ You can add some common metrics by using the instrument middleware:: (use '[metrics.ring.instrument :only (instrument)]) (def app (instrument app)) This will add a number of metrics, listed below. This middleware works great with Noir, too. ring.requests.active ~~~~~~~~~~~~~~~~~~~~~~~~ A counter tracking the number of currently open requests. ring.requests.rate ~~~~~~~~~~~~~~~~~~~~~~ A meter measuring the rate of all incoming requests. ring.requests.rate.* ~~~~~~~~~~~~~~~~~~~~~~~~ Six separate meters (ending in GET, POST, etc) measuring the rate of incoming requests of a given type. ring.responses.rate ~~~~~~~~~~~~~~~~~~~~~~~ A meter measuring the rate of all outgoing responses. ring.responses.rate.* ~~~~~~~~~~~~~~~~~~~~~~~~~ Four separate meters (ending in 2xx, 3xx, etc) measuring the rate of outgoing responses of a given type. ring.handling-time.* ~~~~~~~~~~~~~~~~~~~~~~~~ Six separate timers (ending in GET, POST, etc) measuring the time taken to handle incoming requests of a given type. Troubleshooting --------------- If you're using these extras alongside Noir you'll need to be running the latest version of Noir to avoid dependency issues. If you're getting errors about overriding stuff in Jackson this is the problem. 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.