/*
 * Return express middleware that measures overall performance.
 */
function factory(parentClient) {
    return function (prefix, options) {
        var client = parentClient.getChildClient(prefix);
        options = options || {};

        return function (req, res, next) {
            var startTime = new Date();

            // Shadow end request
            var end = res.end;
            res.end = function (chunk, encoding) {
                end.apply(res, arguments);

                client.timing('response_time', startTime);
                client.increment('response.' + res.statusCode);
            };
            next();
        };
    };
}

module.exports = factory;

@@ -227,16 +227,116 @@
 s %7C%7C %7B%7D;
+%0A        var timeByUrl = options.timeByUrl %7C%7C false%0A        var onResponeEnd = options.onResponseEnd
 %0A%0A      
@@ -514,23 +514,8 @@
 on (
-chunk, encoding
 ) %7B%0A
@@ -613,24 +613,24 @@
 startTime);%0A
-
             
@@ -680,16 +680,555 @@
 usCode);
+%0A%0A                if (timeByUrl && req.route && req.route.path) %7B%0A                    var routeName = req.route.path;%0A                    // need to get rid of : in route names, remove first /, and replace rest with _%0A                    routeName = routeName.replace(/:/g, %22%22).replace(/%5C//, %22%22).replace(/%5C//g, %22_%22);%0A                    client.timing('response_time.by_url.' + routeName, startTime);%0A                %7D;%0A%0A                if (onResponseEnd) %7B%0A                    onResponseEnd(client, startTime, req, res);%0A                %7D;
 %0A       

add in suppport for timing each express route and make the middleware more extendable