从Influxdb查询数据并将其存储到测量中(表)

时间:2021-09-19 16:57:08

I'm new to using InfluxDB and I have what I think is a relatively simple question that I cannot find the answer to. How can I query data from an existing measurement and write that data into another measurement, while storing the name of the measurement where that data came from?

我是新手使用InfluxDB,我认为这是一个相对简单的问题,我无法找到答案。如何从现有测量中查询数据并将该数据写入另一个测量,同时存储数据来源的测量名称?

For example, say I had the measurement

例如,说我有测量

name: temperature

名称:温度

time | external | internal | machine

时间|外部|内部|机

100 | 25 | 40 | unit42

100 | 25 | 40 | unit42

Is there a way I could grab some of that data and the measurement name and put it into a new table? Like this:

有没有办法可以获取一些数据和测量名称并将其放入新表中?喜欢这个:

name: aggregate table

name:聚合表

time | measurment | external | machine

时间|测量|外部|机

100 | temperature | 25 | unit42

100 |温度| 25 | unit42

to be clear, I've looked up the into method, but I can't find a way to also store the name of the measurement Thanks!

要清楚,我已经查找了into方法,但我找不到一种方法来存储测量名称谢谢!

1 个解决方案

#1


0  

To my knowledge, there is no way to turn a measurement name into a tag or field using a query. It's possible that you could use another tool like kapacitor to do what you're trying to do.

据我所知,无法使用查询将测量名称转换为标记或字段。您可以使用其他工具(如kapacitor)来执行您要执行的操作。

That being said, typically the aggregate table is given the same name as the original table, but in a different retention policy. For example

话虽这么说,通常聚合表的名称与原始表的名称相同,但在不同的保留策略中。例如

$ influx
> create database tempdb
> use tempdb
Using database tempdb
> create retention policy my_rp on tempdb duration 0s replication 1
> insert temperature,machine=unit24 external=100,internal=40
> SELECT mean(internal) as internal, mean(external) as external INTO tempdb.my_rp.temperature FROM temperature GROUP BY *
name: result
------------
time    written
0       1
> SELECT * FROM tempdb.my_rp.temperature
name: temperature
-----------------
time    external    internal    machine
0       100         40          unit24

This way you still maintain the name, but the measurement is scoped to another retention policy.

这样您仍然可以维护名称,但测量范围限定为另一个保留策略。

#1


0  

To my knowledge, there is no way to turn a measurement name into a tag or field using a query. It's possible that you could use another tool like kapacitor to do what you're trying to do.

据我所知,无法使用查询将测量名称转换为标记或字段。您可以使用其他工具(如kapacitor)来执行您要执行的操作。

That being said, typically the aggregate table is given the same name as the original table, but in a different retention policy. For example

话虽这么说,通常聚合表的名称与原始表的名称相同,但在不同的保留策略中。例如

$ influx
> create database tempdb
> use tempdb
Using database tempdb
> create retention policy my_rp on tempdb duration 0s replication 1
> insert temperature,machine=unit24 external=100,internal=40
> SELECT mean(internal) as internal, mean(external) as external INTO tempdb.my_rp.temperature FROM temperature GROUP BY *
name: result
------------
time    written
0       1
> SELECT * FROM tempdb.my_rp.temperature
name: temperature
-----------------
time    external    internal    machine
0       100         40          unit24

This way you still maintain the name, but the measurement is scoped to another retention policy.

这样您仍然可以维护名称,但测量范围限定为另一个保留策略。