Reputation: 644
Is there a way to round a decimal value in grafana? round()
and ceil()
functions gets an "instant-vector", not a numeric value, and for example, adding a query like ceil(1/15)
will return 0
.
Upvotes: 10
Views: 33909
Reputation: 17850
PromQL provides round() function, which can be used for rounding query results to the nearest multiple of the second arg. For example, round(q, 1)
rounds q
results to the nearest integer, while round(q, 0.1)
rounds q
results to the nearest multiple of 0.1
. Prometheus doesn't allow passing plain scalars (aka numeric constants) into round()
function. This can be solved by wrapping the numeric constant into vector() function. For example, the following query returns 0.3
:
round(vector(1/3), 0.1)
Upvotes: 4
Reputation: 316
It depends what you're using to display the data, for example a single stat or gauge you'll find the 'Decimals' option in Grafana, for graphs it's in the 'Axes' options. You don't need to do this in the query for the metric.
Upvotes: 7