Is there a way to convert the output of the rate
function in Prometheus to a whole number?
I'm trying to get the total number of pod restarts over a specified timeframe and although this query produces output, I get the result in decimals which isn't what I need.
rate(kube_pod_container_status_restarts_total{namespace=~"jenkins"}[10h]) * 60 * 5 > 0
What I get back is 0.21761280931586605
but I'd rather get a whole number.
I'm just not sure what function to use.
You can use the following functions to round a decimal number:
See more details about the "round" function in the Prometheus documentation here.
In your case, you're using "rate" so you get the number of restarts per second 60 5. Which is the same as the number of restarts every 5 minutes.
But, if you want to count the number of restarts (and not calculate the rate of restarts), maybe you should use the "increase" function instead.
See more details about the "increase" function in the Prometheus documentation here.
You probably don't want to use rate. I'm guessing you're looking for increase which will count how many restarts have occurred over a time period
increase(kube_pod_container_status_restarts_total{namespace=~"jenkins"}[10h])