select host, time as currentTime, floor((1 - (
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'idle'
and time <= h.time
group by host
) / ((
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'idle'
and time <= h.time
group by host
) + (
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'system'
and time <= h.time
group by host
) + (
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'user'
and time <= h.time
group by host
))) * 100) as utilization
from "DendroTimestreamDB"."hostMetrics" h
group by host, time
返回错误line 20:3: Given correlated subquery is not supported但根据Timestream 子查询支持
Timestream 查询语言支持相关子查询和其他子查询。
列:
cpuMode, 主机, 设备, cpuCode, 收集器, measure_value::double, measure_name, time,
样本数据:
空闲,MacBook-Pro.local,-,0,cpu,115950.13,cpu_seconds_total,2021-04-29 13:46:11.000000000
期望的输出:
主机、时间、利用率
MacBook-Pro.local 2021-04-29 13:47:56.000000000 15
MacBook-Pro.local 2021-04-29 13:47:41.000000000 16
MacBook-Pro.local 2021-04-29 13:47:26.000000000 19
我正在尝试使用公式 (1 - idleTime / totalTime) * 100 计算 CPU 利用率,但显然不支持这些相关的子查询。我只需要以不同的方式重写它吗?
在求和子查询中,我试图计算在主查询之前收到的度量值的总和,我正在使用and time <= h.time导致查询相关的行来执行此操作,从而导致问题。
万分感谢