knyar / nginx-lua-prometheus

Prometheus metric library for Nginx written in Lua
MIT License
1.46k stars 231 forks source link

eliminating unique-identifier in URL path #138

Closed divyak8 closed 2 years ago

divyak8 commented 2 years ago

how can we replace account id's and subscription id's in original URL with {subscription ID} , {account ID}.

dolik-rce commented 2 years ago

You can use Lua standard library to modify the values before you pass them to the library. The details depends on how your urls look like, but very naive example for metric that counts requests per method and url could look like this:

local location = ngx.var.uri:gsub("/subscription/.*/", "/subscription/<ID>/"):gsub("/account/.*/", "/account/<ID>/")
request_count_total:inc(1, {location, ngx.var.request_method})

This would count request to /account/12345/details with label /account/<ID>/details.