@@ -101,13 +101,26 @@ function errForLog(err) {
101101function wrapRouteHandlers ( route , app ) {
102102
103103 route . router . stack . forEach ( ( routerLayer ) => {
104- let path = ( route . path + routerLayer . route . path . slice ( 1 ) )
104+ const path = ( route . path + routerLayer . route . path . slice ( 1 ) )
105105 . replace ( / \/ : / g, '/--' )
106106 . replace ( / ^ \/ / , '' )
107107 . replace ( / [ / ? ] + $ / , '' ) ;
108- path = app . metrics . normalizeName ( path || 'root' ) ;
109108 routerLayer . route . stack . forEach ( ( layer ) => {
110109 const origHandler = layer . handle ;
110+ const metric = app . metrics . makeMetric ( {
111+ type : 'Histogram' ,
112+ name : 'router' ,
113+ prometheus : {
114+ name : 'express_router_request_duration_seconds' ,
115+ help : 'request duration handled by router in seconds' ,
116+ staticLabels : app . metrics . getServiceLabel ( ) ,
117+ buckets : [ 0.01 , 0.05 , 0.1 , 0.3 , 1 ]
118+ } ,
119+ labels : {
120+ names : [ 'path' , 'method' , 'status' ] ,
121+ omitLabelNames : true
122+ }
123+ } ) ;
111124 layer . handle = ( req , res , next ) => {
112125 const startTime = Date . now ( ) ;
113126 BBPromise . try ( ( ) => origHandler ( req , res , next ) )
@@ -117,13 +130,7 @@ function wrapRouteHandlers(route, app) {
117130 if ( statusCode < 100 || statusCode > 599 ) {
118131 statusCode = 500 ;
119132 }
120- const statusClass = `${ Math . floor ( statusCode / 100 ) } xx` ;
121- const stat = `${ path } .${ req . method } .` ;
122- app . metrics . endTiming ( [
123- stat + statusCode ,
124- stat + statusClass ,
125- `${ stat } ALL`
126- ] , startTime ) ;
133+ metric . endTiming ( startTime , [ path || 'root' , req . method , statusCode ] ) ;
127134 } ) ;
128135 } ;
129136 } ) ;
0 commit comments