sysulq / nginx-vts-exporter

Simple server that scrapes Nginx vts stats and exports them via HTTP for Prometheus consumption
https://sysulq.github.io/nginx-vts-exporter/
MIT License
645 stars 142 forks source link

Understanding the requests metric #17

Closed Nalum closed 7 years ago

Nalum commented 7 years ago

I'm not sure if I get it or not so just wanted to ask to be sure.

Should the first prometheus query result in the same value as the second prometheus query?

1.

sum(rate(nginx_server_requests{code="total", host="example.com"}[1h])) without (instance, kubernetes_pod_name)

2.

sum(rate(nginx_server_requests{code!="total", host="example.com"}[1h])) without (instance, kubernetes_pod_name, code)

If they should be the same, I think there is an issue as I'm seeing a discrepency. I get the values below for these two queries.

1.

1.2092047487499653

2.

1.2089258466921395
sysulq commented 7 years ago

Maybe you should read this prometheus docs about without operator, hope this would be helpful.

https://prometheus.io/docs/querying/operators/#aggregation-operators

These operators can either be used to aggregate over all label dimensions or preserve distinct dimensions by including a without or by clause.

<aggr-op>([parameter,] <vector expression>) [without|by (<label list>)] [keep_common]
parameter is only required for count_values, quantile, topk and bottomk. without removes the listed labels from the result vector, while all other labels are preserved the output. by does the opposite and drops labels that are not listed in the by clause, even if their label values are identical between all elements of the vector. The keep_common clause allows keeping those extra labels (labels that are identical between elements, but not in the by clause).
Nalum commented 7 years ago

That talks about the labels being different, which is not what my question is about.

I guess my question is really should code="total" be equal to the sum of the other code values? If it is i would expect the output of the two queries above to be the same.

sysulq commented 7 years ago

Maybe you could try the same PromSQL twice, and you will also see the difference :-)

sysulq commented 7 years ago

And yes, code="total" should be equal to the sum of the other code values absolutely