I am attempting to create a dashboard within Chronograf to monitor a Hashicorp Nomad Cluster. I’m attempting to create an overall CPU Allocation % metric from the values that are collected by Telegraf.
Below is the Fluxlang code I’ve used to come up with the CPU%.
nomad_unallocated_cpu =
from(bucket: “telegraf/autogen”)
|> range(start: dashboardTime)
|> filter(fn: ® =>
r._measurement == “nomad_client_unallocated_cpu” AND
r._field == “gauge” AND
r.datacenter == “devops”
)
|> aggregateWindow(every: 30s, fn: mean)
|> group(by: ["_time"])
|> sum()
|> window(every: inf)
nomad_allocated_cpu =
from(bucket: “telegraf/autogen”)
|> range(start: dashboardTime)
|> filter(fn: ® =>
r._measurement == “nomad_client_allocated_cpu” AND
r._field == “gauge” AND
r.datacenter == “devops”
)
|> aggregateWindow(every: 30s, fn: mean)
|> group(by: ["_time"])
|> sum()
|> window(every: inf)
return join(
tables: {unallocated_cpu:nomad_unallocated_cpu, allocated_cpu:nomad_allocated_cpu},
on: ["_time", “_stop”, “_start”]
)
|> map(fn:® => ({
_time: r._time,
_value: (1.0 - r._value_unallocated_cpu / (r._value_unallocated_cpu + r._value_allocated_cpu)) * 100.0
}))
|> yield()
This works and gives me the data that I require, however when creating a dashboard within Chronograf that data is not rounded to the nearest percentile. The “decimal” places functionality within Chronograf does not seem to work. Is there a “round()” function within Flux to round the data?