Reputation: 11
I have a Node JS app that has a URL like this:
/app/:vehicleNumber/details
It takes vehicle numbers dynamically in URL.
The prom-client based metrics API for HTTP calls is returning all the URLs as separate URLs instead of clubbing them as a single URL with vehicleNumber as a variable.
http_request_duration_seconds_bucket{le="0.003",status_code="200",method="GET",path="/app/GJ98T0006/details"}
http_request_duration_seconds_bucket{le="0.003",status_code="200",method="GET",path="/app/KA28T6511/details"}
.....
I want the count based on a single URL. e.g.
http_request_duration_seconds_bucket{le="0.003",status_code="200",method="GET",path="/app/{var}/details"}
It is happening when a UUID is present in the URL but not for vehicle numbers present in the URL.
Upvotes: 1
Views: 2731
Reputation:
Assuming you're using Express, you likely want something like:
let path = null;
if (req.route && req.route.path) {
path = req.baseUrl + req.route.path;
} else if (req.baseUrl) {
path = req.baseUrl;
} else {
/*
* This request probably matched no routes. The
* cardinality of the set of URLs that will match no
* routes is infinite, so we'll just use a static value.
*/
path = '(no match)';
}
path
will be /app/:vehicleNumber/details
. The req.route
part may not be necessary for your use case, but it doesn't hurt -- it comes in to play if you're using express.Router({ mergeParams: true })
to compose your routes.
Upvotes: 1