influxdb - 在对一段时间内的值进行求和后,如何获得 influxdb 中的前 5 个结果

标签 influxdb

根据 InfluxDB 中的以下测量结果,我想在 Grafana 中显示一个表格,其中包含给定传感器最常出现的设备的前 2 个结果。 因此,以下数据的预期结果将是一个包含 2 条数据的表格

device                               total
------                               ----
345678                               7
234567                               3
> select * from incoming_events_by_device limit 50;
name: incoming_events_by_device
time                device                               host   metric_type sensor    value
----                ------                               ----   ----------- ------    -----
1535575550000000000 123456                               foo.com counter     efg       1
1535575550000000000 123456                               foo.com counter     efg       1
1535575550000000000 234567                               foo.com counter     efg       1
1535575550000000000 234567                               foo.com counter     hij       2
1535575550000000000 234567                               foo.com counter     efg       1
1535575550000000000 345678                               foo.com counter     nice      1
1535575550000000000 358168                               foo.com counter     nice      1
1535575550000000000 345678                               foo.com counter     nice      1
1535575550000000000 345678                               foo.com counter     nice      4
1535575550000000000 345678                               foo.com counter     efg       1
1535575550000000000 345678                               foo.com counter     efg       12

我尝试过使用这样的子查询,但没有得到预期的结果。它显示空响应。

SELECT top(incoming_devices_count,5) FROM (SELECT sum(device) as incoming_devices_count FROM incoming_events_by_device WHERE sensor='nice' AND time > now() - 30m group by device)

最佳答案

找到查询。

select top(total, 3), device from (select sum(value) as total from incoming_events_by_device where sensor='nice' AND time > now() - 30m group by device);

关于influxdb - 在对一段时间内的值进行求和后,如何获得 influxdb 中的前 5 个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52103298/

相关文章:

python - 如何解决 Telegraf 中的此错误?

time-series - influxDB 中的运算符之间

golang influxdb 客户端对数组或 slice 的响应

python-3.x - 使用influxdb-python的Influxdb批量插入

influxdb - 使用 api 创建 grafana 仪表板

influxdb将不同系列但相同时间间隔的grafana图的第一个值度量相加

influxdb - Fluxd 和 influxdb 之间丢失数据

curl - 使用 CURL 在 InfluxDB 中插入行

mysql - 如何从 MariaDB 迁移到 InfluxDB 日期时间到时间

database - 在influxdb中合并不同粒度的时间序列