New to NRQL, our team has a requirement to produce reports that show the total cpu hours used per container across namespaces in our K8s clusters. The report time scale defaults to the current month.
Our initial attempt at calculating this:
SELECT average(cpuUsedCores) FROM K8sContainerSample facet containerName SINCE 1 MONTH AGO WHERE clusterName = 'clustername' and namespace = 'namespace' TIMESERIES
However, this produces inaccurate results. For example, if a container was only active for 1 hour and consumed .5 cpu cores, the average comes back as .5 cores over 1 day.
Then we attempted to get more fine-grained data back, like so:
SELECT average(cpuUsedCores) as 'Average CPU Cores Used' from K8sContainerSample facet containerName SINCE '2020-01-01 12:00:00' until '2020-01-15 11:59:59' where clusterName = 'clustername' and namespace = 'namespace' TIMESERIES 1 hour
This does bring back the per-hour average but since we are limited to 366 buckets per query we would have to make 2 calls to get back data for the whole month.
We realize that taking this approach also requires us to parse the results, tally up the core usage count and multiply by the current number of hours in the report
Is there a better way to handle this, ideally in a single query?