knyar / nginx-lua-prometheus

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

feature request: expose request url endpoint with metric latency #108

Closed frodood closed 4 years ago

frodood commented 4 years ago

hello Knyar,

currently latency logged with only "host", is it possible to get the metric with "host" and "endpoint", for example, request is coming to example.com/checkout/buy.php, I would like to know what the latency for the endpoint, nginx_http_request_duration_seconds_bucket{host="example.com", endpoint="/checkout/buy.php",le="00.010"} 42

knyar commented 4 years ago

This is currently possible with this library. The examples in README.md are just that -- examples. In your specific environment you would most likely need to define your own set of metrics and metric labels.

Note that adding HTTP path as a metric label is a very easy way to increase metric cardinality (see this discussion). If you naively use ngx.var.uri as a label value, a simple http scan will suddenly create lots of new metrics which will increase load on your nginx and prometheus server. So in practice you would normally want to derive a limited set of values from HTTP path.