InfluxDB 写入具有相同时间戳但不同测量值的点

InfluxDB write points with same timestamp but different measurement

要求: 我想创建一个 influxDB 数据库来存储来自多个传感器的时间序列数据,这些传感器报告来自不同位置的温度。

问题: 当我用相同的时间戳但不同的标签(例如:位置)和字段(温度)值将点写入数据库时​​,涌入会用最新的时间戳覆盖标签和字段值

我遵循了他们网站上提供的文档,他们显示了一个符合上述要求的示例数据库,但我找不到使用的模式。

Example Table with duplicate timestamps

附加信息: 示例输入:

json_body_1 = [
{
    "measurement": "cpu_load_short",
    "tags": {
        "host": "server02",
        "region": "us-west"
    },
    "time": "2009-11-10T23:00:00Z",
    "fields": {
        "Float_value": 0.7,
        "Int_value": 6,
        "String_value": "Text",
        "Bool_value": False
    }
},
{
    "measurement": "cpu_load_short",
    "tags": {
        "host": "server01",
        "region": "us-west"
    },
    "time": "2009-11-10T23:00:00Z",
    "fields": {
        "Float_value": 1.0,
        "Int_value": 2,
        "String_value": "Text",
        "Bool_value": False
    }
}]

我使用了官方文档中给出的例子,仍然不是2条记录,我只得到一条。请注意主机标签是不同的,理想情况下应该使每个点都独一无二。

Documentation

今天我也遇到了同样的问题,现在我来解决一下。 :)

from influxdb import InfluxDBClient

client = InfluxDBClient(host='host name', port=8086, database='test_db',username='writer', password=Config.INFLUXDB_WRITE_PWD)

points = [{
    "measurement": "cpu_load_short",
    "tags": {
        "host": "server02",
        "region": "us-west"
    },
    "time": "2009-11-10T23:00:00Z",
    "fields": {
        "Float_value": 0.7,
        "Int_value": 6,
        "String_value": "Text",
        "Bool_value": False
    }
},
{
    "measurement": "cpu_load_short",
    "tags": {
        "host": "server01",
        "region": "us-west"
    },
    "time": "2009-11-10T23:00:00Z",
    "fields": {
        "Float_value": 1.0,
        "Int_value": 2,
        "String_value": "Text",
        "Bool_value": False
    }
}]

status = client.write_points(json_body_1, database='test_db', batch_size=10000, protocol='json')

这是输出

> select * from cpu_load_short;
name: cpu_load_short
time                Bool_value Float_value Int_value String_value host     region
----                ---------- ----------- --------- ------------ ----     ------
1257894000000000000 false      1           2         Text         server01 us-west
1257894000000000000 false      0.7         6         Text         server02 us-west