Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus return no data when calculating a ratio of two metrics

I want to calculate a ratio of two metrics, but I get no data...

I have some metrics like:

fs_bytes{filesystem="/var",instance="localhost:9108",job="graphite",metric="Used"}   50.0
fs_bytes{filesystem="/var",instance="localhost:9108",job="graphite",metric="Total"}   100.0

When I try to do any operation (device, multiply, add, subtract) like:

fs_bytes{instance="localhost:9108",metric="Used"} / fs_bytes{instance="localhost:9108",metric="Total"}

Prometheus returned:

no data

When I query each metric alone in the Prometheus expression browser, I do get the metrics values.

What's wrong?

like image 807
Franklin Piat Avatar asked Jun 28 '18 10:06

Franklin Piat


People also ask

How do you use the rate function in Prometheus?

Prometheus rate function is the process of calculating the average per second rate of value increases. You would use this when you want to view how your server CPU usage has increased over a time range or how many requests come in over a time range and how that number increases.

What is offset in Prometheus?

The offset modifier allows changing the time offset for individual instant and range vectors in a query. For example, the following expression returns the value of http_requests_total 5 minutes in the past relative to the current query evaluation time: http_requests_total offset 5m.

What is the difference between rate and irate in Prometheus?

rate() is generally used when graphing the slow moving counters. While irate() is used when graphing the high volatile counters.

What is increase function in Prometheus?

Prometheus' increase function calculates the counter increase over a specified time frame². The following PromQL expression calculates the number of job executions over the past 5 minutes. increase(job_execution_total[5m]) Since our job runs at a fixed interval of 30 seconds, our graph should show a value of around 10.


1 Answers

When prometheus is evaluating an expression, the operation implicitly apply to metric that share identical set of labels.

Despite the fact I specified the metric name and most labels, Prometheus was looking for metrics that have the same set of labels.

However, in this case, two metrics have different label values, so they can't match ! (one metric has metric="Used"the other has metric="Total". It could be that one of the metrics has some extra labels).

The solution is to use ignore (or on) to reduce the set of considered labels:

fs_bytes{instance="localhost:9108",metric="Used"} / ignoring(metric) fs_bytes{instance="localhost:9108",metric="Total"}

Read the fine manual ! (here)

like image 162
Franklin Piat Avatar answered Oct 25 '22 11:10

Franklin Piat