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
.
How to round an decimal value Grafana
Asked Answered
Edit: Datasource is prometheus. The example is based on this documentation –
Felipe
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.
Yes, but i need it in a query, not as a transformation of the result. e.g:
sum(some_metric{property="some_value"}) + ceil($param / 15)
Is this possible? –
Felipe It should yeah, can you post the actual error you're getting? From your OP it sounds like it was saying something like " expected type instant vector in call to function "round", got scalar" is that true? If so to test you could wrap it in vector: EG in the Prometheus console ceil(1/15) will fail, but ceil(vector(1)/15) will return 1, round 0 –
Midlands
That's the answer @andy!. I was missing the
vector(<esclar>)
part. –
Felipe 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)
© 2022 - 2024 — McMap. All rights reserved.