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?
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.
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.
rate() is generally used when graphing the slow moving counters. While irate() is used when graphing the high volatile counters.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With