statsd-client
Advanced tools
Comparing version 0.0.10 to 0.0.11
/* | ||
* Return express middleware that measures overall performance. | ||
* | ||
* The `prefix` defaults to `''` (but is currently mandatory). The | ||
* `options`-argument is optional. | ||
* * You can set `timeByUrl`, that add a timer per URL template (ex: | ||
* `/api/:username/:thingie`). This can be changed run-time by setting | ||
* `res.locals.statsdUrlKey`. | ||
* * Add a `function(client, startTime, req, res)` in `onResponseEnd` that | ||
* will be called at the very end. | ||
*/ | ||
@@ -19,14 +27,25 @@ function factory(parentClient) { | ||
client.timing('response_time', startTime); | ||
client.increment('response.' + res.statusCode); | ||
if (timeByUrl && req.route && req.route.path) { | ||
var routeName = req.route.path; | ||
if (Object.prototype.toString.call(routeName) === '[object RegExp]') { | ||
// Might want to do some sanitation here? | ||
routeName = routeName.source; | ||
var routeName; | ||
// Did we get a harc-coded name, or should we figure one out? | ||
if (res.locals && res.locals.statsdUrlKey) { | ||
routeName = res.locals.statsdUrlKey; | ||
} else { | ||
routeName = req.route.path; | ||
if (Object.prototype.toString.call(routeName) === '[object RegExp]') { | ||
// Might want to do some sanitation here? | ||
routeName = routeName.source; | ||
} | ||
if (routeName === "/") routeName = "root"; | ||
routeName = req.method + '_' + routeName; | ||
} | ||
if (routeName === "/") routeName = "root"; | ||
// need to get rid of : in route names, remove first /, and replace rest with _ | ||
routeName = req.method + '_' + routeName.replace(/:/g, "").replace(/\//, "").replace(/\//g, "_"); | ||
client.timing('response_time.by_url.' + routeName, startTime); | ||
// Get rid of : in route names, remove first /, and replace | ||
// rest with _. | ||
routeName = 'response_time.' + routeName.replace(/:/g, "").replace(/\//, "").replace(/\//g, "_"), | ||
client.timing(routeName, startTime); | ||
} else { | ||
client.timing('response_time', startTime); | ||
} | ||
@@ -33,0 +52,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"keywords": ["statsd", "client", "metrics", "udp"], | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"homepage": "https://github.com/msiebuhr/node-statsd-client", | ||
@@ -9,0 +9,0 @@ "bugs": "https://github.com/msiebuhr/node-statsd-client/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27470
624